Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing caret characters with sed

Tags:

regex

sed

caret

I have lines in a file that look like this:

FA General,1234567^^^^^FA Student Letter- General^<<undefined>>^\\path\to\file.RTF

I'm trying to use sed to replace the caret characters with commas. If I use:

sed 's/\^/,/' file.txt

Nothing changes. I've also tried

sed 's/\\^/,/' file.txt
sed 's/^^/,/' file.txt

What am I missing here?

like image 754
Ben Wall Avatar asked Mar 23 '26 23:03

Ben Wall


1 Answers

Do you want to replace all carets? I am sure if you look closely at your result you'll see that the first caret is replaced. So try this:

sed -e 's/\^/,/g' file.txt

Note the g to mean global replace, i.e, all matches.

like image 56
mplwork Avatar answered Mar 26 '26 11:03

mplwork



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!