<Any suggestion how to create a file where the values are separated by ASCII code 1,with data extracted from a table using shell script The format is :/>
<columnname1(binary1)columnvalue(binary1)columnname2(binary1)columnvalue(binary1)columnname3(binary1)columnvalue... 1st row/>
<columnname1(binary1)columnvalue(binary1)columnname2(binary1)columnvalue(binary1)columnname3(binary1)columnvalue.. second row/>
Pure shell script does NOT work at all well with binary data. The main reason is that binary data will have the ASCII 0 character. For shell, this character marks the end of a string. I would try using the dd command instead. For a start on this.
What OS do you have
are the binary "fields" all exactly the same length, e.g., pick one: 4 bytes, 8 bytes, etc.
can you work with writing simple C code? or perl? This may be another option for you.
Hi dasun...
As a starting point you could try something like this and is fully POSIX compliant...
Longhand on OSX 10.14.3, default bash terminal calling dash purely as a demonstration:
What happens in the above nice example when there is a 00 character? I do not think it will work as required. I do not have your system, but on mine (opensuse 13, bash, and dash) I get short fields (fewer bytes).
This is purely a demonstration and shows it can be done and with modifications the idea might suit the OP.
However, the OP specifically asked for Ctrl-A, 0x01...
So depending on ANY 8 bit field separator:
#!/usr/local/bin/dash
: > /tmp/FILE
CSV()
{
# The OP specifically asked for Ctrl-A, 0x01 but for any binary...
printf "\000"
} >> /tmp/FILE
# First line...
printf '<' >> /tmp/FILE
for TEXT in text1 text2 text3
do
printf "${TEXT}" >> /tmp/FILE
CSV
done
echo 'text4/>' >> /tmp/FILE
# Second line...
printf '<' >> /tmp/FILE
for TEXT in text5 text6 text7
do
printf "${TEXT}" >> /tmp/FILE
CSV
done
echo 'text8/>' >> /tmp/FILE
# And so on...
# Check it works...
hexdump -C /tmp/FILE
# How it views using 'cat'...
cat /tmp/FILE