Is there a clear method to write the following with pipes avoiding the temp file(s) redirection?
awk '{gsub("Sat ", "Sat. ");print}' Sat.txt >win.txt
awk '{gsub(" 1-0", "");print}' win.txt >loss.txt
awk '{gsub(" 0-1", "");print}' loss.txt >draw.txt
awk '{gsub(" 1/2-1/2", "");print}' draw.txt >$TARGET
You can have as many gsub()
as you want in awk
. Each one of them will replace $0
, so every time you will be working with the modified string.
However, note you can compress the gsub()
into just two of them by using some regular expressions:
awk '{gsub("Sat ", "Sat. "); gsub(/ (1-0|0-1|1\/2-1\/2)/, "")}1' file
# ^^^ ^^^ ^^^^^^^^^
# 1-0 0-1 1/2-1/2
The first one replaces Sat
with Sat.
and the second one removes space + either of 1-0
, 0-1
or 1/2-1/2
.
$ cat a
hello Sat is now and 1-0 occurs there when 0-1 results happen but 1/2-1/2 also
bye
$ awk '{gsub("Sat ", "Sat. "); gsub(/ (1-0|0-1|1\/2-1\/2)/, "")}1' file
hello Sat. is now and occurs there when results happen but also
bye
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments