Help in removing control M and Line feed in output file.

Hi All,

In my output file i am getting control m character and also the line feeds at different places and with different combinations, the content of the file is supposed to be in a single line but if there is a line feed in between then from there onwards it's going into new line.

I tried removing the ^M char but this is not working and line feed is creating an issue. : tr -d "^M" < "$taxt_file" > a.txt

Please help me in handling this.

Thanks in Advance.
Bipin

Looks like the file was imported from a windows/dos environment. Try the command

dos2ux filename

or

dos2unix filename

to remove the CRLF characters.

With awk , try this:

awk '{ sub(/\r$/,""); print }' file

Edit:

awk '{sub(/\r$/,"")}1' file
tr -d "\015" < "$taxt_file" > a.txt

Almost nobody has dos2unix, but tr -d '\r' < inputfile > fixedfile will work anywhere.

1 Like

Usually, the line end sequence is <carriage return><line feed>, so those anchored sub s won't work . Why anchor at all?

Line feeds are what the anchor, anchors to.

Oh yes, you are right. My fault, I was coming from another direction. Sometimes it helps to think before saying/writing sth.