?
Solved

Shell script to read bytes from a file

Posted on 2005-03-14
10
Medium Priority
?
764 Views
Last Modified: 2008-02-01
Hello,

Could someone please give me an example (if this is possible), of how to read a file using a uCLinux shell script to read a data file.

Specifically, the file contains two 4-byte records.  I would like to read each byte into an individual variable, and then take an action, depending on the byte value.  For example, if the value of the first byte = 0x01, run program x, if it is 0x02, run program y etc.

Since I am still new to Linux, a detailed example would be appreciated.

Thanks in advance!
0
Comment
Question by:quiTech
9 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 13537964

Maybe you should check here first: http://www.uclinux.org/
0
 
LVL 48

Expert Comment

by:Tintin
ID: 13539795
Not the easiest thing to do in a shell script, however it's very easy with Perl or C.
0
 

Author Comment

by:quiTech
ID: 13540224
Yes, doing it in C would be relatively straight forward.  The only concern is that any C program I compile ends up taking up at least 30k, even if it doesn't do anything.  Since space is at a premium on this device, I hoping that perhaps a script would be more compact (if not as quick).

0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 48

Expert Comment

by:Tintin
ID: 13540433
Well, I suppose you could parse the output from

od filename

Something like:

od -x filename | awk '/0000000/ {print $2,$4}' >/tmp/$$
byte1=`cat /tmp/$$ |cut -c1-2`
byte2=`cat /tmp/$$ |cut -c3-4`
..

Not the most efficient (I'm sure there's probably a better way of doing it).



0
 

Author Comment

by:quiTech
ID: 13545981
thanks Tintin.  It doesn't look like "od" is supported on this implementation of uCLinxu.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13546336
on a embedded system you most likely go better with a small compiled program than using what the system offers ('cause this might be limited)
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13573399
are you stripping the program which you compiled in c .striping considerably reduces the size of the program .
#strip prog-name

surya.
0
 
LVL 3

Expert Comment

by:mike_mian
ID: 13576874
you could always try a bitwise &-ing and evaling the results?  
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 13772978
Submitted to PAQ with no points refunded (of 500)

DarthMod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question