?
Solved

Shell script to read bytes from a file

Posted on 2005-03-14
10
Medium Priority
?
745 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

764 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