Tuesday, January 28, 2014

Shell - List number of lines once the search pattern matches

awk '/PATTERN/ {for(i=1; i<=5; i++) {getline; print}}' filename

The above command will search the key word "PATTERN" once it is matched, it will print the below 5 lines after the search string from the text file.