New line characters in Ascii file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New line characters in Ascii file
# 1  
Old 05-11-2010
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 ...

Code:
@
@
@
@
@
@
@
@
"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.

Code:
 
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)


Code:
 
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

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

still i am not getting the output in unix similar to wordpad/ultra edit.
# 2  
Old 05-11-2010
do you have dos2unix?

or
Code:
cat file | tr -d '\015' > new_file

should do it.

Last edited by zaxxon; 05-11-2010 at 06:23 AM.. Reason: use code tags please, ty
This User Gave Thanks to bigearsbilly For This Post:
# 3  
Old 05-11-2010
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:
Code:
tr -s '\015' '\n' < infile > outfile

This User Gave Thanks to zaxxon For This Post:
# 4  
Old 05-11-2010
If none of the above solution works, maybe you can attach that file for further tests?
# 5  
Old 05-11-2010
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)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Lower ASCII characters.

Hi, I'm writing a BBS telnet program. I'm having issues with it not displaying lower ASCII characters. For example, instead of displaying the "smiley face" character (Ctrl-B), it displays ^B. Is this because i'm using Ncurses? If so, is there any way around this? Thanks. (3 Replies)
Discussion started by: ignatius
3 Replies

2. Shell Programming and Scripting

Convert UTF-8 file to ASCII/ISO8859-1 OR replace characters

I am trying to develop a script which will work on a source UTF-8 file and perform one or more of the following It will accept the target encoding as an argument e.g. US-ASCII or ISO-8859-1, etc 1. It should replace all occurrences of characters outside target character set by " " (space) or... (3 Replies)
Discussion started by: hemkiran.s
3 Replies

3. Shell Programming and Scripting

Identify extended ascii characters in a file

Hi, Is there a way to identify the lines in a file having extended ascii characters and display the same? For instance I have a file abc.txt having below data aaa|bbb|111|This is first line aaa|bbb|222|This is secõnd line aaa|bbb|333|This is third line aaa|bbb|444|This is foùrth line... (3 Replies)
Discussion started by: decci_7
3 Replies

4. Shell Programming and Scripting

Removing these non-ASCII characters from a file

Hi, I have many text files which contain some non-ASCII characters. I attach the screenshots of one of the files for people to have a look at. The issue is even after issuing the non-ASCII removal commands one of the characters does not go away. The character that goes away is the black one with a... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

5. Shell Programming and Scripting

How to check if the file has EBCDIC or ascii characters

Hi, is there a way to check if the initial few characters are ebcdic or ascii in a file? (1 Reply)
Discussion started by: ahmedwaseem2000
1 Replies

6. Shell Programming and Scripting

convert ascii values into ascii characters

Hi gurus, I have a file in unix with ascii values. I need to convert all the ascii values in the file to ascii characters. File contains nearly 20000 records with ascii values. (10 Replies)
Discussion started by: sandeeppvk
10 Replies

7. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

8. Shell Programming and Scripting

Weird Ascii characters in file names

Hi. I have files in my OS that has weird file names with not-conventional ascii characters. I would like to run them but I can't refer them. I know the ascii # of the problematic characters. I can't change their name since it belongs to a 3rd party program... but I want to run it. is there... (2 Replies)
Discussion started by: yamsin789
2 Replies

9. Shell Programming and Scripting

Multibyte characters to ASCII

Hello, Is there any UNIX utility/command/executable that will convert mutlibyte characters to standard single byte ASCII characters in a given file? and Is there any UNIX utility/command/executable that will recognize multibyte characters in a given file name? The typical multibyte... (8 Replies)
Discussion started by: jerardfjay
8 Replies

10. HP-UX

Hex characters of ascii file

Hi, Whats the command or how do you display the hexadecimal characters of an ascii file. thanks Bud (2 Replies)
Discussion started by: budrito
2 Replies
Login or Register to Ask a Question