LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-07-2007, 07:02 AM   #1
ksrinivas
LQ Newbie
 
Registered: Sep 2006
Posts: 15

Rep: Reputation: 0
ascii file read/printing in Linux


Hi All,

I am trying to read a bit file (in ASCII format) and printing the same on console.
If i open the file i could see the following data:
">^H^D^L*^M^L^M^L<80>^L^X<8c>^@^@<80>p^H^B^@H08^B^@x^@^^^@<80>^@^@^@^@^@< 80>^@^@^@^@^@^@^@^@^@<88>^@^@^@^@^@<80>^B^@<80>^@^@^@^@^@^@<80>^@^H^@^@^ @^@^@<80>^@<80>^@^@^@^@^@^@^@^L^L<80>^@^@^D<80>^@^@^@^@^@^@^@<80>^@^@^@< 80>^@<80"

but when i am trying to print using %c or %d i could not able to match the both.

Is there any way to print the same ???

Please give me some suggestions on this.

Thanks
Srinivas
 
Old 01-07-2007, 07:14 AM   #2
FnordPerfect
Member
 
Registered: Dec 2006
Location: Germany
Distribution: Kubuntu (Feisty Fawn), Debian (SID)
Posts: 127

Rep: Reputation: 15
> but when i am trying to print using %c or %d i could not able to match the both.

Sorry, but I don't quite get what you are trying to do!
Are you just trying to display the while with a file reader or text editor, or are you trying to open and print it from within a C program you are coding?

Anyway, it doesn't look as if it is a plain ASCII file you have there. Perhaps it is compressed some way? could you check with the 'file' utility what type of content is in the file?
 
Old 01-07-2007, 07:20 AM   #3
ksrinivas
LQ Newbie
 
Registered: Sep 2006
Posts: 15

Original Poster
Rep: Reputation: 0
when i use file utility "data" is displayed.
MyFile.bit: data

- Srinivas
 
Old 01-07-2007, 07:32 AM   #4
ksrinivas
LQ Newbie
 
Registered: Sep 2006
Posts: 15

Original Poster
Rep: Reputation: 0
Just to add one more point here is, I am using Open() system call to open the file and then read() system call to read the file and then copying the data to a buffer and then printing the same (in C program).

Thanks
Srinivas
 
Old 01-07-2007, 08:38 AM   #5
FnordPerfect
Member
 
Registered: Dec 2006
Location: Germany
Distribution: Kubuntu (Feisty Fawn), Debian (SID)
Posts: 127

Rep: Reputation: 15
Oh dear... I thought it had something to do with C. Sorry, I am not a programmer.

But there is Programming forum here at the site, that would be a better place to
post this!

But here is what I think:
It is not the reading that fails, but the output to your terminal emulator.
A plain ASCII file would contain only alphanumeric characters, interpunctation, etc., but your file contains binary data.
Terminal emulators tend to get confused by full 8bit output, since they interpret some bytes as control sequences. If you remember programming under DOS, you also got into trouble if you wanted to print out the first 32 ASCII characters, for the very same reason.
 
Old 01-07-2007, 09:16 AM   #6
anupamsr
Member
 
Registered: Sep 2004
Location: India
Distribution: Kubuntu, Archlinux, Suse, Gentoo, Mandrake
Posts: 370

Rep: Reputation: 30
May be this will help:
http://www.metalshell.com/view/source/27/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
line numbering in ASCII file rohr Programming 4 03-18-2005 10:14 AM
bash printing extended ASCII characters nutthick Programming 6 02-04-2005 03:15 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 11:24 PM
Printing a linux ASCII file in windows ChimpFace9000 Linux - General 2 05-05-2002 07:00 PM
Displaying a text file in ascii?? bauld Linux - General 4 11-21-2001 08:33 PM


All times are GMT -5. The time now is 12:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration