New line characters in Ascii file

I am having a file(1234.txt) downloaded from windows server (in Ascii format).However when i ftp this file to Unix server and try to work with it..i am unable to do anything.When i try to open the file using vi editor the file opens in the following format ...

@
@
@
@
@
@
@
@
"1234.txt" 1 line, 73232 characters

I believe the whole file is being treated as a single line.

when i view the file using more command...the following is the output...where i could see the end-of-line charaters(^M) similar to binary file opened in vi editor.

 
more 1234.txt

00:06:00 CARD TAKEN^M 00:06:01 TRANSACTION END^M*901*05/05/2010*00:45*^M *TRANSACTION START*^M CARD INSERTED^MCARD: *****************^MDATE 05-05-10 TIME 00:45:11^M 00:4
5:22 PIN ENTERED^M*902*05/05/2010*00:45*^M *9561*1*w*0, M-00, R-0

The same file if i open using wordpad or ultraedit in windows,the following is the output (the correct format)

 
00:06:00 CARD TAKEN
00:06:01 TRANSACTION END
*901*05/05/2010*00:45*
*TRANSACTION START*
CARD INSERTED
CARD: *****************
DATE 05-05-10 TIME 00:45:11
00:45:22 PIN ENTERED
*902*05/05/2010*00:45*
*9561*1*w*0, M-00, R-0

I am not sure where i am making mistake.

I tried FTP in ASCII as well as binary format and i tried the following awk command as suggested by Franklin 52 in one of the similar post earlier

 
awk '{printf "%s\r\n", $0}' 1234.txt >> 1234.txt1

still i am not getting the output in unix similar to wordpad/ultra edit.

do you have dos2unix?

or

cat file | tr -d '\015' > new_file

should do it.

1 Like

As it seems there is no newline at the end of line anymore, but just the windows <cr>. On Unix side you can try to replace the ^M with \n like this:

tr -s '\015' '\n' < infile > outfile
1 Like

If none of the above solution works, maybe you can attach that file for further tests?

Thanks a million guys...

The solution provided by ZAXXON worked ...

The solution provided by bigearsbilly was also correct...i just had to add the newline character for it to work(Which is also the solution provided by Zaxxon)