I found on stackoverflow this awk about printing from match (row4) ( link ), combined with the feature to process several files due to resetting the match indicatior each time a new file is being opened. Input file1, file2 and file 3 look like this each time:
row1;something;in;this;row;;;;;;;
row2;something;in;this;row;;;;;;;
row3;something;in;this;row;;;;;;;
row4;don't;need;to;match;the;whole;line,;
row5;something;in;this;row;;;;;;;
row6;something;in;this;row;;;;;;;
row7;something;in;this;row;;;;;;;
row8;something;in;this;row;;;;;;;
row9;something;in;this;row;;;;;;;
row10;something;in;this;row;;;;;;;
Output should be this:
works something in this row
row6 something in this row
row8 something in this row
row9 something in this row
row10 something in this row
works something in this row
row6 something in this row
row8 something in this row
row9 something in this row
row10 something in this row
works something in this row
row6 something in this row
row8 something in this row
row9 something in this row
row10 something in this row
In the original thread here link it says one can simply add
... $1=="row5"{$6=$5; $5=""} ...
in order to 'move' fields if match condition is true to the command:
awk 'FNR==1{p=0} p; /row4/{p=1} ' file1 file2
But where do I have to add this? I tried all combinations I saw and it did not work. In my case I also want to delete a line after match "row 7" and and change field $1 if it is == "row 5"
if ($1=="row7") {next};
if ($1=="row5") {$1="works"}
In my case I put the rules into a file: test.awk and save it for later use. This I call then in this way:
gawk -f test.awk *.csv
( file1.csv, file2.csv and file3.csv). The two new conditions are still being ignored also if I put these before the p rule:
FNR==1 {p=0}
$1=="row5" {$5="works"}
$1=="row7" {next}
p;
/row4/{p=1}