awk - How can I delete one line before and two after a string? -
You enter a record in a text file that looks like this:
Header Data 1 Data 2 Data 3
I would like to delete the entire record if data is 1 given string I think this requirement requires awk which I do not know.
Awk record can handle these multilog records by separator in an empty string:
BEGIN {rs = ""; ORS = "\ n \ n"} $ 2 == "some string" {next} # Skip this record {print} # print (non-skipped) records
You can save a file (like remove.awk
) and send it to awk -f remove.awk data.txt & gt; Newdata.txt
Believes that your data is of the format:
header data .... header data ...
< / Ex>If there is no blank line between records, then you have to divide the records manually (this is 4 lines per record):
{a [ ++ i] = $ 0} I == 2 & amp; Amp; A [i] == "some strings" {skip = 1} i == 4 & amp; Amp; ! Skip {print (i = 1; i & lt; = 4; i ++) Print a [i]} i == 4 {skip = 0; I = 0}
Comments
Post a Comment