0

I have a file similar to the following:

random,test123,MyCompany, Inc.
hello,12345,TestCompany, LLC

I want to remove the commas from the third column so I'd have something like this:

random,test123,MyCompany Inc.
hello,12345,TestCompany LLC

How would I do this?

2
  • 1
    You mean third occurrences of comma? Sep 20, 2017 at 11:39
  • If the first two "columns" contain a comma somewhere, then both answers below (and any others that are general enough to be useful) will fail. If that's the case, then you will have to do some manual editing. Otherwise, either answer works fine.
    – NickD
    Sep 20, 2017 at 12:28

2 Answers 2

5

This is easy with sed:

sed 's/,//3' file

Try it online!

If you want to directly apply the modifications in your input file, then run:

sed -i 's/,//3' file
0

With awk:

awk -F, '{print $1,$2,$3$4}' OFS=',' file

The output:

random,test123,MyCompany Inc.
hello,12345,TestCompany LLC

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .