Computing.Net > Forums > Unix > printing all lines after grep using awk

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

printing all lines after grep using awk

Reply to Message Icon

Name: AngelFlesh
Date: October 26, 2009 at 09:06:22 Pacific
OS: Windows Vista
Subcategory: General
Tags: grep, awk
Comment:

I am trying to extract lines after a grep command
this is what i have so far

/sbin/chkconfig --list | grep 'xinetd based services'

there is about 20 lines after the grep that i need, it may not always be 20 lines so how do i print till end of file?

would awk be useful here?



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: October 27, 2009 at 01:41:30 Pacific
Reply:

don't have to use grep together with awk. Just awk will do

/sbin/chkconfig --list | awk '/search_pattern/,0'

GNU win32 packages | Gawk


0

Response Number 2
Name: tvc
Date: October 31, 2009 at 06:59:59 Pacific
Reply:

Yes, you can use AWK instead of GREP, but it does not make any sense

The threadstarter has a different question though, but what exactly is not clear ... either limit the output with TAIL or HEAD, or use another GREP (or AWK) command


0

Response Number 3
Name: ghostdog
Date: October 31, 2009 at 23:26:21 Pacific
Reply:

threadstarter, aka OP, says he wants to print from the grabbed pattern till the end of line. The awk solution does just that. Grep, although can search for the pattern, it will only display the lines that match the patterns, not the lines after it matches. you can use -A or -B to display number of lines before and after, BUT the number of lines in OP's case is not known beforehand. therefore, it makes sense to use awk, rather than grep

GNU win32 packages | Gawk


0

Response Number 4
Name: user57
Date: November 3, 2009 at 06:34:43 Pacific
Reply:

To print the line with the search_pattern and all lines there after:

/sbin/chkconfig --list | awk '/xinetd based services/ {f=1}f'


0

Response Number 5
Name: tvc
Date: November 7, 2009 at 02:18:10 Pacific
Reply:

You're right Ghost, I missed the question just a little there.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: printing all lines after grep using awk

grep - print next line too www.computing.net/answers/unix/grep-print-next-line-too/7417.html

print the next line www.computing.net/answers/unix/print-the-next-line/6313.html

Substituting on the line above the match www.computing.net/answers/unix/substituting-on-the-line-above-the-match/2931.html