can someone please help me to fix this script,
I have a 2 files, one file has hostname information and second file has console information of the hosts in each line, I have written a script which actually reads each line in hostname file and should grep in the console file and paste the information in the third file, but not sure, I am not getting the desire o/p in third file it is just a blank file.
and Consoles file has 5000 line and hostname file has 500 line
I was writing these scripts non of them working please suggest.
#!/bin/bash
while read line
do
grep -i '$line' /scripting/consoles >> /scripting/output
done < /scripting/hostlist.txt
#!/bin/bash
/bin/date > /scripting/found.txt
/bin/date > /scripting/notfound.txt
while read line
do
echo "checking" $line;
sleep 2
if [[ `/bin/grep $line /scripting/consoles` != "" ]];
sleep 1
then
echo "$line found in /scripting/consoles file"
echo "$line" >> /scripting/found.txt
sleep 1
else
echo "$line not found in /scripting/consoles file"
echo "$line" >> /scripting/notfound.txt
fi
done < /scripting/hostlist.txt
I think I confused you,
Input files that I provided are just sample file and host file has around 500 lines, each line is hostname and it should search in console file which as 5000 enteries.
....
sed 's/\r//' $hfile | while read line ; do
...
done
...
which will gt rid of those pesky windowsy carriage returns (\r). Otherwise you're grepping for string AND a carriage return, which not matching anything.
I suggest you use variables for filenames instead of hard-coding them and quote the output of grep in case it's more than one word:
cfile=/scripting/consoles
if [[ "`/bin/grep $line $cfile`" != "" ]] ; then