用 sed 替换插入字符 [英] Replacing caret characters with sed

查看:39
本文介绍了用 sed 替换插入字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件中有如下几行:

I have lines in a file that look like this:

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

我正在尝试使用 sed 将插入符号替换为逗号.如果我使用:

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

我在这里遗漏了什么?

推荐答案

是否要替换所有插入符号?我敢肯定,如果您仔细查看结果,您会发现第一个插入符号已被替换.所以试试这个:

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

注意 g 表示全局替换,即所有匹配.

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

这篇关于用 sed 替换插入字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆