Replacing caret characters with sed

烈酒焚心 提交于 2020-06-12 15:28:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!