0

I have this inline sed command:

sed -e 's/^M/\'$'\n/g' filename.txt

which is working inline, but not inside a bash script:

#!/bin/bash
sed -e 's/^M/\'$'\n/g' $1

Removing \'$' from the code doesn't solve the problem (replaces ^M with just an "n").

Cheers, Andrea

1 Answers1

0

In #!/bin/bash you need to use $'\r' instead of ^M

You can use the tr (translate) command

#!/bin/bash
tr -d $'\r' < $1

See: remove ^M characters from file using sed for a solution for removing carriage return

Community
  • 1
  • 1
F.Igor
  • 4,119
  • 1
  • 18
  • 26