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!

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
  • Great thanks! I was hoping this would be a simple fix. – Michael James Feb 25 '15 at 21:18
  • +1 for removing the unnecessary use of cat. – David Foerster Feb 25 '15 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.