-2

I have the following file :

/
/FUSE
//
Bank S.A / N.V
/F

I want to remove all forward slashes (/), so that the result looks like this:


FUSE

Bank S.A N.V F

How to do so using sed? Ive tried using tr, but tr is not what I need, because I want to edit the file in-place without printing it to console.

  • You appear to have deleted the last line in the example output. Is that a requirement of any solution here too? – Kusalananda May 10 '22 at 15:21

3 Answers3

4

You can use tr for this:

$ tr -d '/' < file

FUSE

Bank S.A N.V F

To save the output, just redirect to a new file:

tr -d '/' < file > file.fixed
Kusalananda
  • 333,661
terdon
  • 242,166
3

Use a different separator than / into the sed expression, for example ::

sed 's:/::g' file

to remove all / irrespective of where they are on the line.

If you want to replace the existing file, use -i, meaning "inplace", which can be followed by an extension to backup the old file, for example this will keep a copy of the old file named file.old and modify file:

sed -i.old 's:/::g' file
thanasisp
  • 8,122
0

You can also use sed this way:

sed --in-place 's/\///g' file

You just ask sed to substitute (s) pattern / with void space.