user3684156
user3684156

Reputation: 31

Not able to remove ^M characters in a file - shell script

I'm not able to remove the special character from file.

File Contents : a.lst

errordetails^M grd^M gpr^M

sed "s/^M//" a.lst > b.lst

b.lst also contains the special character

Upvotes: 0

Views: 147

Answers (1)

Haifeng Zhang
Haifeng Zhang

Reputation: 31905

sed -ibak 's/\^M//g' a.lst

-i is to modify a.lst directly, bak is to backup your original file

(\\) back slash is to escape the specific character ^

^ means the beginning of a line, which you need to escape it.

g is a global flag, for example "^M123^Mabcd^M", you can only remove the 1st "^M" without the global flag.

Edit:

echo "errordetails^M grd^M gpr^M" | sed 's/\^M//g'
errordetails  grd  gpr

Upvotes: 1

Related Questions