Help with sed/grep

Hi,

I have a file with reoccurring patterns and I want extract the 3rd line after the match, then delete another pattern from that third line.

For example the file is in the following format:

Hello
Name: Abc
Number: 123

Hello
Name: FQE
Number: 543

This occurs more than 100 times:
I want to be able to pull out the third line after Hello then extract the number so I'll have a number list like
123
543
Etc..

Thanks

one way:

awk -F':'  '/^Number/ {print $2} ' infile > newfile
awk '/Hello/{getline;getline;print $NF}' file
1 Like

A more dynamic awk solution where you can change to number of lines by adjusting the value of p
awk ' /Hello/ {p=2+1} {p--} !p {print $NF}' file

Edit: some more optimized
awk '{p--} /Hello/ {p=2} !p {print $NF}' file

Try also

awk '/Hello/ {L=NR+2} NR==L {print $2}' file
123
543
2 Likes