how to create flat file delimited by "\002"

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

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

Thanks guys. printf worked.

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