I have a text file like this:
$ cat test
12 13 2100 s
12 13 3100 s
100 13 100 s
12 13 300 s
I want the output to be like this:
$ cat test
12 13 22000 s
12 13 32000 s
100 13 2000 s
12 13 300 s
I only want to replace 100
in field 3 (once 100
is contained in $3
) into 2000
. How can I accomplish this job using awk
?
Here's one way using awk
:
awk '{ sub(/100$/, "2000", $3) }1' file
Results:
12 13 22000 s
12 13 32000 s
100 13 2000 s
12 13 300 s
Try:
awk '{$3=gensub(100,2000,1,$3);print}' test.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With