Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

regex - Replacing caret characters with sed

I have lines in a file that look like this:

FA General,1234567^^^^^FA Student Letter- General^<<undefined>>^\pathofile.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...