Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
843 views
in Technique[技术] by (71.8m points)

regex - Match from pattern to end of file in bash

I have been trying to figure out how to use grep in a bash script to match from a pattern to the end of the file. The file is not always the same number of lines each time and is not always [A-Za-z0-9]. I'm trying to migrate from a flat-file based catalog to a database.

File excerpt:

First, Last: Doe, John
ID: xxxxxxxx
...

Case Notes:

This "person" does not exist!  
Please do not add him. 
Thanks.

I need to grab everything from Case Notes: to the end of file. I can't seem to find anything to help out there as there isn't an actual EOF character.

Ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

An awk script might be easier:

awk '/^Case Notes:$/ { matched = 1 } matched'

Or if you don't want to see the Case notes: string itself, reverse it:

awk 'matched; /^Case Notes:$/ { matched = 1 }'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...