问题
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?
回答1:
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.
回答2:
Or try the y
command:
sed 'y/^/,/'
来源:https://stackoverflow.com/questions/15687044/replacing-caret-characters-with-sed