shell script find a line and the next line (grep?)
Lets say I have the following text file
Code:
name Code:
phone: I'm sure there is a way but I have yet to find it. |
grep -A1 phone $file
This only works with GNU grep. Normal grep doesn't have -A (after) option ( see also -B => before) |
Awk
Awk can handle multiline records by specifying the field separator to be a newline and set the record separator to an empty string. |
Here's an example using sed.
Code:
sed -n '/phone/,+1 p' file.txt |
All great answers.
Thanks!!! |
Code:
awk '/phone/{where=NR;print}NR==where+1 && where!=0 {print}' file |
All times are GMT -5. The time now is 01:58 AM. |