0

I have a file which contains 6 columns, each field separated by "I" the second last column contains amount field.

140121059|01/01/201400:00:45|[1390]|[387]|17.64|10
140121060|01/01/201400:00:46|[1112]|[867]|26.46|10
140121062|01/01/201400:00:47|[182]|[13]|4,117.60|10
140121065|01/01/201400:00:48|[1088]|[385]|1,147.04|10

I want to remove "," from the amount column as Im not able to put some operations on this column. "," is not coming in all columns. And Im using bash.

  • Judging by your sample input you could just delete all commas everywhere with tr -d , < file.txt > output – jw013 Jul 29 '14 at 16:51
2

You can use awk:

$ awk -F'|' '{sub(",","",$(NF-1))}1' OFS='|' file
140121059|01/01/201400:00:45|[1390]|[387]|17.64|10
140121060|01/01/201400:00:46|[1112]|[867]|26.46|10
140121062|01/01/201400:00:47|[182]|[13]|4117.60|10
140121065|01/01/201400:00:48|[1088]|[385]|1147.04|10

$(NF-1) refers to the second to last field, we only replace comma in this field.

If you want to remove comma in all field, you can use tr instead:

$ <file tr -d ',' > out_file 
0

Assuming your file contains comma only in the amount field, you can use the command as below.

 sed 's/,//g' filename
0

I would just use sed:

sed 's/,//g' filename

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.