azrosen92
azrosen92

Reputation: 9107

Using sed to get text starting at a line number and ending with a reg expression pattern

I want to be able to extract text in a bash script using sed starting at a certain line number and ending at a given pattern. Right now I have sed "${LINE_NUM}p;d" $FROM_FILE, but that only returns the text on line number $LINE_NUM. What if I want to get text starting at $LINE_NUM going all the way down to some pattern of text?

Upvotes: 1

Views: 150

Answers (1)

jaypal singh
jaypal singh

Reputation: 77175

You can do:

sed -n "${LINE_NUM},/regex/p" "$FROM_FILE"

Be sure to use word boundary \b for text to get a perfect match instead of fuzzy.

Upvotes: 1

Related Questions