General Shell Script

Shell script for filter IP address from file or URL and save in ROW format

 

#!/bin/sh
# Shell script for filter IP address from file or URL and save in ROW format
file_Name=$( basename $0 .sh )
tmp_Dir=/tmp
a=1
#Filter IP address from file and save in host_ip in tmp location
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' $tmp_Dir/hosts.cfg > $tmp_Dir/host_ip
echo -e "********************************" > $tmp_Dir/host_ip_list
echo "IP List" >> $tmp_Dir/host_ip_list
echo -e "********************************" >> $tmp_Dir/host_ip_list
# create Header tab
echo -e "Host_Name_1 \t" >> $tmp_Dir/host_ip_list "Host_Name_2 \t" >> $tmp_Dir/host_ip_list "Host_Name_3 \t" >> $tmp_Dir/host_ip_list
# Read input from file and arrange in tab format
for i in `cat $tmp_Dir/host_ip`
do
echo -e "$i \t\c" >> $tmp_Dir/host_ip_list
if [ $a -gt 2 ]
then
echo >> $tmp_Dir/host_ip_list
a=0
fi
a=`expr $a + 1`;
done

Output:-

image_thumb2

**************************************************

Leave a Reply

Your email address will not be published. Required fields are marked *