Hi,
I'm trying to figure out a way to find which line in my file.txt with IP addresses:
192.168.0.1
192.178.0.2
etc...
returns specific result when I execute command affecting all lines.
For example when I run:
for line in `cat file.txt`;
do
snmpget $line
done
it displays the results from all lines but I cant tell which line returns which result. Any help on this?
Try:
for line in `cat file.txt`;
do
echo "Line: $line"
snmpget $line
echo
done
What about adding an echo "This is the line $line"
for line in `cat file.txt`;
do
echo "This is the line $line"
snmpget $line
echo "-------------------------"
done
PS:- Oops, I think Bartus and I posted right around the same time :).
You get a useless use of cat award with useless use of backticks on the side. There's almost never a good reason to do this when the shell has a faster, simpler builtin without the unpredictable side-effects(data gets silently ignored, or program dies with 'too many arguments', or spaces cause the line to split early, etc, etc, etc)
while read LINE
do
...
done < filename
Great guys! It works just right!
If it's not too much to ask - is there a way to output the result on the same line:
not like
192.168.0.1
"result from command"
but as 192.168.0.1 "result of command"
Thanks again for your help!
Use printf
instead of echo
while read line
do
printf $line
snmpget $line
done < file.txt
--ahamed