I have a comma seperated csv file as a sample like:

1,92345,92345,Dear user, this is your amount , 2016-10-10 
2,92345,92345,Dear user, this is your amount , 2016-10-09

I need to replace 4th comma , only after the Dear user with a pipeline |.


Using sed, you can specifically tell sed which occurrences of pattern only you want to replace, so:

sed 's/,/|/4' infile

Or with different solution would be:

sed -r 's/^([^,]*,)([^,]*,)([^,]*,)([^,]*),(.*)/\1\2\3\4|\5/' infile

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.