dan sawyer
dan sawyer

Reputation: 193

sed conditional replace single character csv file

The problem is removing , errors in text files. The error is the ',' after M.D

xxx","M.D,","abc","xxx

The desired string is to replace the single , after D with a .

xxx","M.D.","abc","xxx

There are over 30 fields in the line

Upvotes: 0

Views: 116

Answers (2)

Arnab Nandy
Arnab Nandy

Reputation: 6692

As an alternate solution try this command as follows;

sed 's/M.D,/M.D./g' filename

Output:

$ sed 's/M.D,/M.D./g' sample

xxx","M.D.","abc","xxx

Upvotes: 1

karakfa
karakfa

Reputation: 67467

I don't know all your cases but for inits this may work

$ echo 'xxx","M.D,","abc","xxx' | sed -r 's/([A-Z]),/\1./'
xxx","M.D.","abc","xxx

Upvotes: 1

Related Questions