injey
December 28, 2010, 4:53pm
1
I need to create a flat file with columns delimited by "\002" (octal 2)
I tried using the simple echo.
name="Adam Smith"
age=40
address="1 main st"
city="New York"
echo ${name}"\002"${age}"\002"${address}"\002"${city} > mytmp
but it creates a delimiter with different octal code.
Adam Smith^T0^Q main st^BNew York
Please help
rdcwayx
December 28, 2010, 7:30pm
2
replace echo
by printf
Sample for you.
printf "%s \002 %s \002" ${name} ${age}
1 Like
name="Adam Smith"
age=40
printf "%s\002%s" "${name}" "${age}" > outfile
xxd -a outfile
1 Like
injey
December 28, 2010, 9:04pm
4
Thanks guys. printf worked.
methyl
December 29, 2010, 7:00am
5
Just for interest the "echo" version can be made to work by creating the delimiter separately to avoid interaction with any numbers in the final echo statement.
name="Adam Smith"
age=40
address="1 main st"
city="New York"
delimiter=`echo "\0002\c"`
echo "${name}${delimiter}${age}${delimiter}${address}${delimiter}${city}" > mytmp