What i am doing is , i tail a file from certain chatacter and then cat -n to get the line numbers.I search for a particular string and gets it line number. What i am interested in is the next line immediately after the pattern i search.
But grep gives me result for all line statring with those digits.
For Ex:
I got the pattern in line as:
10 Pattern i searched.
Now, I need contents of line 11(i store in variable say $next_line).
so i do :
tail -c [number] | grep "^[[:space:]]* $next_line
But it gives me result for the lines like 11, 111, 110 and so on .
Is there a way to only search for the exact number in grep.
Thanks for reply.
Yes, you are right, i just track numbers to get the contents, but the thing is there are several lines in file with the same contents i grep. So i process them one by one . Also its on different boxes, i do ssh and use this. By line number i keep track which i processed and which didn't.
Will be good if i get something in grep itself or anything which allows only to search the exact number.
Ok, not sure how you correlate the stuff you get via ssh, but basically processing a file step by step should be no problem. Here is an example with awk, where the pattern is more than once in the file (if I undestood correct):
$> cat infile
1 one
2 two
3 three
4 one
5 two
6 four
7 five
8 one
9 two
10 one
$> awk '/two/ {getline; print}' infile
3 three
6 four
10 one
I added numbers so you can see that it is working on all three patterns it found which is in this case "three"
awk processes the whole file so you could put something it should do with the found patterns (ie. the following line) into the curled brackets.