user1308144
user1308144

Reputation: 475

selective printing

I have large files that I want to do some selecting printing on. I want to find a line based on a pattern match and print this line, and all following lines up to the end of the file. I would use sed, however, the match is only based on the first and second column.

awk '{if($1=="XYZ" && $2=="GT") print $0}' in.file > out.file

How can I change the above to also print all lines following the match.

Upvotes: 2

Views: 452

Answers (3)

jfg956
jfg956

Reputation: 16748

For me, your sed approach was fine. If the separator is ;:

sed -n -e '/^XYZ;GT;/,$p' your_file

Upvotes: 1

Scrutinizer
Scrutinizer

Reputation: 9936

Or try using a range pattern:

awk '$1=="XYZ" && $2=="GT",end' file

Upvotes: 1

Thor
Thor

Reputation: 47189

Use a printing flag:

awk '$1=="XYZ" && $2=="GT" { f = 1 } f' in.file > out.file

The f is set to 1 when the two conditions are met. The lone f at the end of the script invokes the default block { print $0 } when 1.

Upvotes: 3

Related Questions