Linux Scripting
Hey guyz,
lets say i have this template. xxxx AAA xxxx Total number of bytes =xx total uplink rate = xx Lets say i grep for xxxx AAA xxxx from there i want to get the whole line for 3 lines down how do i do that? means final out put i want the xx from total uplink rate |
Hey There,
Gnu's version of grep has a -A argument grep -A 3 yourString -B works the same way, except the argument is the number of lines Before your match to get your line and the 3 lines following. You can also do it with sed. Hope that helps :) , Mike |
hey.. its not working..
cat test.sh | grep -A 2 for grep: illegal option -- A Usage: grep -hblcnsviw pattern file . . . ^[cat test.sh | grep -B grep: illegal option -- B Usage: grep -hblcnsviw pattern file . . . |
hey it works
i was using it on a SUN platform earlier thats why |
On the sun, you could try using awk:
awk '/xxxx AAA xxxx/{ end=NR+3 } NR <= end { print $0 } NR > end { end = 0 }' file If you don't want the xxxx AAA xxxx line printed: awk '/xxxx AAA xxxx/{ end=NR+3; start=NR+1 } NR <= end && NR >= start { print $0 } NR > end { end = 0 }' simple Code:
~> cat file |
All times are GMT -5. The time now is 10:28 AM. |