1834142 Members
2304 Online
110064 Solutions
New Discussion

Re: read in file

 
SOLVED
Go to solution
Bhoyet Orillo
Occasional Contributor

read in file

Is there a way to read a specified number of bytes in
a file using a script?
4 REPLIES 4
Steven Sim Kok Leong
Honored Contributor
Solution

Re: read in file

Hi,

Following will read just the first 8 bytes from your input file (whether in binary or text).

# dd if=input_file bs=1 count=8

Hope this helps. Regards.

Steven Sim Kok Leong
Bhoyet Orillo
Occasional Contributor

Re: read in file

Thanks for that quick reply. But where does the read bytes go. Is there an internal buffer?
Steven Sim Kok Leong
Honored Contributor

Re: read in file

Hi,

You can redirect the read bytes either to a file (use -of option or > redirection) or you can pipe it somewhere else (use |). If neither is used, it will be displayed as STDOUT.

Hope this helps. Regards.

Steven Sim Kok Leong
James R. Ferguson
Acclaimed Contributor

Re: read in file

Hi:

You can also capture it directly into a variable of your choice. For instance:

# X=`dd if=/etc/hosts bs=1 count=60`
# echo $X

Regards!

...JRF...