I would like to change the content of the file that has few blocks starts with 10 and ends with ";"
File1.txt
10 bonuses D
20 MATCHED
30 UPD COL
40 (SOL=30)
20 NOT MATCHED
30 INS COL
40 (SOL=30)
;
10 bonuses D
20 MATCHED
30 UPD COL
40 (SOL=20)
20 NOT MATCHED
30 INS COL
40 (SOL=50)
;
I've tried using awk to match the sets but could not able to get the output as below - each block has some lines starts with 40 that need to be merged with line starts with 20 with AND and then 40 line needs to be deleted.
output.txt
10 bonuses D
20 MATCHED AND (SOL=30)
30 UPD COL
20 NOT MATCHED AND (SOL=30)
30 INS COL
;
10 bonuses D
20 MATCHED AND (SOL=20)
30 UPD COL
20 NOT MATCHED AND (SOL=50)
30 INS COL
;
I'm trying it to get it achieved. Please provide your valuable suggestions or approches to get it reach the expected output. Thanks!
awk -f sect.awk data
10 bonuses D
20 MATCHED AND (SOL=30)
30 UPD COL
20 NOT MATCHED AND (SOL=30)
30 INS COL
;
10 bonuses D
20 MATCHED AND (SOL=20)
30 UPD COL
20 NOT MATCHED AND (SOL=50)
30 INS COL
;
$
tac file | awk '$1 == 40 {TMP = $2} $1 == 20 {print $0, "AND", TMP} $1 !~ /^[24]0$/' | tac
10 bonuses D
20 MATCHED AND (SOL=30)
30 UPD COL
20 NOT MATCHED AND (SOL=30)
30 INS COL
;
10 bonuses D
20 MATCHED AND (SOL=20)
30 UPD COL
20 NOT MATCHED AND (SOL=50)
30 INS COL
;