Awk Find And Replace Fields Values
foo bar 12,300.50
foo bar 2,300.50
abc xyz 1,22,300.50
foo bar 2,300.50
abc xyz 1,22,300.50
How do I replace all , from 3rd field using awk and pass output to bc -l in the following format to get sum of all numbers:
12300.50+2300.50+1,22,300.50
You can use gsub() funcion as follows. The syntax is:
12300.50+2300.50+1,22,300.50
You can use gsub() funcion as follows. The syntax is:
gsub("find", "replace")
gsub("find-regex", "replace")
gsub("find-regex", "replace", t)
gsub(r, s [, t])
gsub("find-regex", "replace")
gsub("find-regex", "replace", t)
gsub(r, s [, t])
From the awk man page:
You can also use the following syntax:
gensub(r, s, h [, t])
From the awk man page:
Example
Create a data file cat /tmp/data.txt
foo bar 12,300.50 foo bar 2,300.50 abc xyz 1,22,300.50
Type the following awk command:
Sample outputs:
12300.50 2300.50 122300.50
You can pass the output to any command or calculate sum of the fields:
OR build the list and pass to the bc -l:
沒有留言:
發佈留言