Like the following text:
ABCD 1234 FDS
2011 550
1023 832er 1231
The request is processed as follows:
ABCD 1234 FDS
2011 550
total1:1023 Total2:832er 12end
Determine if the last line of text is preceded by the first column with Total1: The second column plus Total2: The third column is followed by minus two characters followed by the end.
Implemented using SED and awk, respectively.
Sed:
Copy Code code as follows:
Echo ' ABCD 1234 FDS
2011 550
1023 832er 1231 ' |sed-r ' $s/([^]*) () ([^]*) () (..). *$/total1:\1\2total:\3\4\5end/'
ABCD 1234 FDS
2011 550
total1:1023 Total:832er 12end
Awk:
Copy Code code as follows:
awk ' Nr>1{print a}{a=$0}end{$1= ' total1: "$1;$2=" Total2: "$2;print gensub (/. $/, "End", $)} ' file
awk ' Begin{getline a}{print a;a=$0}end{$1= total1: $1;$2= ' total2: ' $2;$3=gensub (/. $/, "End", 1,$3);p rint} '
awk ' {if (!getline line) {print ' Total1: "$" total2: "$" gensub (/. $/, "End", 1,$3)}else{print line?$0 RS line:$0}} '