3

I am trying to use sed to remove the equals signs from this file and pipe it to a new file:

I am a file to be edited.
A unique file with my own words.
T=h=e=r=e a=r=e i=s=s=u=e=s w=i=t=h t=h=i=s l=i=n=e

I tried cat FixMeWithSed.txt | sed 's/=//' > FileFixedWithSed.txt but it only replaced the first equals sign.

I am a file to be edited.
A unique file with my own words.
Th=e=r=e a=r=e i=s=s=u=e=s w=i=t=h t=h=i=s l=i=n=e

I am not sure how to select all of the equals signs instead of only the first one. Thanks!

2 Answers 2

5

You have to use the g flag to do a global replacement. Otherwise, it just happens once.

cat FixMeWithSed.txt | sed 's/=//g' > FileFixedWithSed.txt

By the way, sed can read from a file so you don't need cat here:

sed 's/=//g' FixMeWithSed.txt > FileFixedWithSed.txt
2
  • Great thanks! I was hoping this would be a simple fix. Feb 25, 2015 at 21:18
  • +1 for removing the unnecessary use of cat. Feb 25, 2015 at 21:37
1

You can use

sed -i "s/=//g" file.in

to replace = on the same file, without creating a new one. Otherwise you can even use

tr -d '=' < file.in > file.out

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .