another requirement say if in /var/tmp/ there is only one particular line im interested in i.e the second to last line and i want this printed off then move onto the next ip address in /tmp/ip_list
In a earlier post you said that things were printing all over the place. The printf was just so you could see what file each line was comming from.
printf outputs the pathname of the file with ip address slotted in at the %s position eg /var/tmp/1.1.1.1/test.log: , as no CR is on the end of this line the output of head+tail appends on the end.
The "while read ip" statment populates the ip environment variable from the file 1 line at a time. and then executes all code to the done statement.
printf has the format of:
printf format_string arg1 arg2 arg3 ...
Here is a couple of examples - (check man printf for more):
printf "%10s%6.2f\n" test 12
test 12.00
printf "Name: %s Age:%d\n" "John Jones" 25
Name: John Jones Age:25
So:
%10s formats first argument (test) as a 10 wide right justified string (Use %-10 for left justified)
%6.2f formats 2nd argument (12) as 6 (full stop and 2 digits count in width too) wide float with 2 decimal places
%s first argument (John Jones) as a variable width string
%d 2nd argument (25) as variable width integer.