Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I am trying to find an Android shell command that is able to read a file but that has the power to skip, for example 512 bytes every 1024 bytes.

Does such a command exist and is available for Android devices?

I have looked at dd documentation but couldn't figure out if it is possible to use dd for that purpose. You can make dd skip bytes at the beginning of the file, you can make it read X bytes from a file, but I do not see how to get the feature that I described.

EDIT:

For my purpose the command/script should output to stdout, and the processing will read the output like a stream, so it will not be something like "cat a file, do processing, cat a file". It is like "while true; do cat a file; done | processing".

The list of available commands is here: http://www.busybox.net/downloads/BusyBox.html

share|improve this question
add comment

1 Answer

You should try to use this bash script I wrote for you (require busybox on your Android):

put the script in a file called script.bash (change with your own path) :

#!/system/xbin/bash
# sputnick 20120928 http://android.stackexchange.com/posts/30069

binfile=<THE PATH OF YOUR BIN FILE>
bytes=$(wc -c < $binfile)
c=0 count=0

while ((count < bytes - (1024+512) )); do
    dd 2>/dev/null if=$binfile bs=512 count=2 skip=$c
    printf '\n\n'
    ((count += 1024+512 ))
    ((c+=3))
done

Now, in a terminal on your computer (this is for linux, adapt it if you use Windows)

adb push script.bash /mnt/sdcard/script.bash
adb shell
bash
chmod +x /mnt/sdcard/script.bash
/mnt/sdcard/script.bash

edit

This is what the script does in-fine :

dd 2>/dev/null if=/tmp/bin bs=512 count=2 skip=0
dd 2>/dev/null if=/tmp/bin bs=512 count=2 skip=3
dd 2>/dev/null if=/tmp/bin bs=512 count=2 skip=6
dd 2>/dev/null if=/tmp/bin bs=512 count=2 skip=9
(...)
share|improve this answer
    
That certainly should work but I see two details that could be improved for my purpose. First I want it to output to stdout and not to several files. I think you can fix that just by removing the of option. The other thing is, I do not know if calling dd several times brings an overhead of opening/closing the file several times making the process less efficient than it should be. –  Rui Marques Sep 29 '12 at 12:08
1  
The script was edited to fit your needs. If you know a better way than calling dd several times, tell me how ;) –  sputnick Sep 29 '12 at 14:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.