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!

Michael James
  • 275
  • 2
  • 6
  • 15

2 Answers2

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
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
David Foerster
  • 36,264
  • 56
  • 94
  • 147