Dear All,
Is there a way to convert long decimal int value to 4-bytes, using Bourne Shell or any commands from minimal Linux (sed, awk, etc)?
The goal is to calculate size of file and place the 4-byte value before it. I.e:
#!/bin/sh
size=`du filename`
cat <convert $size to 4 bytes> filename >filename
Appreciate your help.
UPD: i have found a part of solution:
n = 12345 # sample long int file size
"let n0 = $n % 256"
"let n = $n / 256"
"let n1 = $n % 256"
"let n = $n / 256"
"let n2 = $n % 256"
"let n = $n / 256"
"let n3 = $n % 256"
echo $n0 $n1 $n2 $n3
So now I have these 4 ints representing bytes. The remaining questions is how to write it as 4 bytes to file?
Is there a way to convert long decimal int value to 4-bytes, using Bourne Shell or any commands from minimal Linux (sed, awk, etc)?
The goal is to calculate size of file and place the 4-byte value before it. I.e:
#!/bin/sh
size=`du filename`
cat <convert $size to 4 bytes> filename >filename
Appreciate your help.
UPD: i have found a part of solution:
n = 12345 # sample long int file size
"let n0 = $n % 256"
"let n = $n / 256"
"let n1 = $n % 256"
"let n = $n / 256"
"let n2 = $n % 256"
"let n = $n / 256"
"let n3 = $n % 256"
echo $n0 $n1 $n2 $n3
So now I have these 4 ints representing bytes. The remaining questions is how to write it as 4 bytes to file?
Comment