how to read ascii file in HP-UX


 
Thread Tools Search this Thread
Operating Systems HP-UX how to read ascii file in HP-UX
# 1  
Old 10-22-2008
how to read ascii file in HP-UX

Hello All,

I need to read the data inside one file who's format is ascii text. I got the file format when I use file command on the file.

file <filename>
filename ascii text

please help me on this.

Thanks
# 2  
Old 10-22-2008
Code:
#!/bin/ksh
while read line
do
 echo "$line"
 echo "this line has ${#line} characters"
done < inputfilename

# 3  
Old 10-22-2008
Thanks for your quick response.

I tried the script and it gives me the the information line wise like how many character are there in each line but the contents are not in readable format.
it gives me below output

] M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?M-^?
this line has 26 characters
]@
this line has 2 characters
^P
# 4  
Old 10-22-2008
Quote:
Hello All,

I need to read the data inside one file who's format is ascii text. I got the file format when I use file command on the file.

file <filename>
filename ascii text

please help me on this.

Thanks
Actually, I am not sure about your requirement. Do you want a command to read ascii files on hpux?

If that's the case, you can do

# more <filename> - Read the file page by page.
# vi <filename> - Edit the file using vi editor (However, it shows the content)
# cat <filename> - Would print the content of a file.

I'm sorry if am talking something irrelevant to situation here since Jim has given a mini script. I wasnt sure, however, if you want to read the content of a file using a command the above should work.

-DB
# 5  
Old 10-22-2008
dos2ux <filename>
# 6  
Old 10-22-2008
Hi DustBunny

Thanks for your reply Yes I want to read file which is in ascii format and then I tried more, cat commands to read but it gives me o/p which is not understandable below is the o/p

^B^B^A^B^B^B^B^B^B^B^B^A^G^B^B^B^A^G^B^A^B^B^A^B^B^B^A^B
^A^B^B^B^B^B^B^B^B^B^B^A^B^B^B^B^B^B^B^B^B^B^B^B^B^B
^A^B^A^B^G^B^B^B^B^B^B^B^A^B^B^B^B^B^B^B^B^B^B^B^B
^B^G^B^A^B^B^B^B^A^B^B^B^B^B^A^B^B^A^B^F^A^B^B^B^B^A^A^A^B
^B^B^A^B^A^B^B^A^B^B^B^B^B^A^B^G^B^B^A^B^A^B^B^B^B^B^B^B
^B^B^A^B^B^B^B^B^A^B^B^B^B^A^B^B^B^B^B^B^B^A^B^A^A^B^B^B
^B^B^B^B^B^B^A^A^A^B^B^B^B^B^B^B^B^A^B^A^B^B^B^B^B^T^B
^G^B^B^B^B^B^B^B^B^B^B^B^B^B^B^B^B^B^A^B^B^B^B^B^B


And the same response from dos2ux command.

I tried the strings command too it gave me the some o/p but not all it chop up the contents while displaying as it reduces the file size.

Last edited by gyanusoni; 10-22-2008 at 08:55 AM..
# 7  
Old 10-22-2008
This is a case of "garbage-in....garbage-out". Your file really is mostly gibberish. These commands are showing you what's there.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert EBCDIC(.DAT) FILE into ASCII FILE

Hi Team, I am having 100 EBCDIC files (i.e. DAT extension) and need to convert them into ASCII File by unix shell script. I tried with DD Command but its not providing output as expected. Sample Text: ------------------ גהאבדוחס@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Expected Output:... (2 Replies)
Discussion started by: JSM
2 Replies

2. Shell Programming and Scripting

Convert Hex to Ascii in a Ascii file

Hi All, I have an ascii file in which few columns are having hex values which i need to convert into ascii. Kindly suggest me what command can be used in unix shell scripting? Thanks in Advance (2 Replies)
Discussion started by: HemaV
2 Replies

3. UNIX for Dummies Questions & Answers

After Ftp'ing file to destination how to check the file if it is in correct ASCII and not corrupted

Hi Folks, While transferring file from FTP software like Filezilla the files gets corrupted. Is there any way I can check if the recently transferred file is in ASCII and not corrupted. I have tried using file -i filename command which does tell if the file character set is ASCII or binary... (6 Replies)
Discussion started by: Khan28
6 Replies

4. Programming

How to read extended ASCII characters from stdin?

Hi, I want to read extended ASCII characters from keyboard using c language on unix/linux. How to read extended characters from keyboard or by copy-paste in terminal irrespective of locale set in the system. I want to read the input characters from keyboard, store it in an array or some local... (3 Replies)
Discussion started by: sanzee007
3 Replies

5. Red Hat

Unable to convert EBCDIC file to ASCII file

Hello all, To give you all a little bit of background. We recently migrated from HP-UX to Redhat Linux and one of the command I used to run on HP-UX to convert an EBCDIC file to ASCII file isn't working on Linux. The code is as follow: cat workout2.dat | dd cbs=250 conv=block conv=ascii... (3 Replies)
Discussion started by: sethmj
3 Replies

6. UNIX for Dummies Questions & Answers

Read an ascii as cell-tabulated form

Hi Guys, I was wondering if it is possible to load a space-tabulated ascii as a "cell-tabulated form", something like excel. I have the following information: tracl tracr fldr ep cdp cdpt nhs duse scalel scalco sx sy counit ns dt igi year day hour minute sec timbas 1 1 1 1 1 1 1 1 -1000... (9 Replies)
Discussion started by: Gery
9 Replies

7. 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

8. 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

9. Shell Programming and Scripting

How to convert English text file to ASCII File?

file abc abc: English text I want to convert the above into file abc file: ascii text (1 Reply)
Discussion started by: laknar
1 Replies

10. UNIX Desktop Questions & Answers

ASCII file

I've been having trouble trying to read an ASCII file. I'm on an IRIX machine, by the way. I've tried "cat" and I get a bunch of unreadable text, and the "string" command gets the "Command not Found" error. Please advise. Thanks. (1 Reply)
Discussion started by: sherbet808
1 Replies
Login or Register to Ask a Question