RHEL 7 system. I have an output file that looks like
eDTG=20210210-1540
Sent 74004956
Completed 72185529 (97.54%)
Lost 18119427 (2.46%)
QPS, SERVFAIL QPS 60122 2905
eDTG=20210210-1601
I've been using sed to change the spacing to tabs for saving as a csv. Now it turns out we need to break the QPS line to 2 separate lines to look like this (note the numbers split between the lines)
eDTG=20210210-1540
Sent 74004956
Completed 72185529 (97.54%)
Lost 18119427 (2.46%)
QPS 60122
SERVFAIL QPS 2905
eDTG=20210210-1601
I can do this with
awk '/QPS/ {printf "QPS\t%s\nSERVFAIL QPS\t%s",$4,$5}' output.txt
But gawk -i inplace is not available so i have the issue with writing to another file. Well of course it only printed the matched line if i didn't put in the ; {print}
option. And then it writes the old line as well. I know there has to be a better way to do this than creating the second file and then copying it back to the first filename (cutting the QPS, ...). I would appreciate any help you can give.
gawk -i inplace
also use temporary file for the inplace job andsed -i
as well – αғsнιη Feb 11 at 20:27awk '/^QPS,/ {printf "QPS\t%s\nSERVFAIL QPS\t%s\n",$4,$5;next} 1' output.txt > output.txt.1 && mv output.txt.1 output.txt
– Uncle Billy Feb 11 at 20:30