Reputation: 341
I want to delete the records in a file once a pattern is found and delete all lines from that pattern until end of the file
I tried doing in awk but I haven't found if there is a simpler way to do it
So I want to match the pattern in the second column and then delete records from that pattern until the end of the file
awk -F"," '$2 ~ /100000/ {next} {print}' file.csv
So the above code skips those lines however as you can see i need to add multiple match patterns to ignore lines after the ones that have the value 100000 in 2nd column are ignored. Please note that the values in 2nd column appear sequentially so after 100000 would come 100001 and there is no fixed end number.
Upvotes: 0
Views: 293
Reputation: 133630
Not sure if I got your problem correctly IMHO I believe you need following.
awk '$2==100000{print;exit} 1' Input_file
This will print till the line whose 2nd column is 100000 and then since you don't want to print anything do in spite of simply reading further file and skipping it, this will exit from code which will additionally save our time too.
OR as per Ed Morton sir's nice suggestion:
awk '1; $2==100000{exit}' Input_file
Upvotes: 2