Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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?

don't have to use grep together with awk. Just awk will do
/sbin/chkconfig --list | awk '/search_pattern/,0'

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

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

To print the line with the search_pattern and all lines there after:
/sbin/chkconfig --list | awk '/xinetd based services/ {f=1}f'

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |