![]() |
grep and display the below lines in file
Hello All
I have a list a file, I want to grep a word and display rest lines after the match was found. for example : 1. 4324 2. 1.234 3. 5467 4. 3.456 5. 2.345 So, if I grep "1.234", I want display the rest after this as : 1. 5467 2. 3.456 3. 2.345 Please advise. Thanks |
Hi
you can try the -A option followed by the number of lines to display after the match I think there are more ways to achieve this with awk or sed grep -A 2 1.234 regards, michael |
Grep, im not so sure of.
But with sed. Code:
~/tmp $ cat tmp |
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
I believe the A,B,C options in grep are only able to print fixed numbers of lines, and can't be told to go "to the end". fukawi1's sed command is probably the best way to go. I'll also add that a gnu extension lets you use "0" instead of "1", to ensure that the address range works when the pattern appears on the first line. Here are a few useful sed references. http://www.grymoire.com/Unix/Sed.html http://sed.sourceforge.net/grabbag/ http://sed.sourceforge.net/sedfaq.html http://sed.sourceforge.net/sed1line.txt The sed faq is especially helpful for cases like this. |
| All times are GMT -5. The time now is 05:05 AM. |