how to create flat file delimited by "\002"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to create flat file delimited by "\002"
# 1  
Old 12-28-2010
Tools 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.

Code:
 
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.

Code:
 
Adam Smith^T0^Q main st^BNew York

Please help
# 2  
Old 12-28-2010
replace echo by printf
Sample for you.
Code:
printf "%s \002 %s \002" ${name} ${age}

These 2 Users Gave Thanks to rdcwayx For This Post:
# 3  
Old 12-28-2010
Code:
name="Adam Smith"
age=40

printf "%s\002%s" "${name}" "${age}" > outfile
xxd -a outfile

This User Gave Thanks to fpmurphy For This Post:
# 4  
Old 12-28-2010
Thanks guys. printf worked.
# 5  
Old 12-29-2010
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.

Code:
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

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Removing duplicates on a single "column" (delimited file)

Hello ! I'm quite new to linux but haven't found a script to do this task, unfortunately my knowledge is quite limited on shellscripts... Could you guys help me removing the duplicate lines of a file, based only on a single "column"? For example: M202034357;01/2008;J30RJ021;Ciclo 01... (4 Replies)
Discussion started by: Rufinofr
4 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Cant get awk 1liner to remove duplicate lines from Delimited file, get "event not found" error..help

Hi, I am on a Solaris8 machine If someone can help me with adjusting this awk 1 liner (turning it into a real awkscript) to get by this "event not found error" ...or Present Perl solution code that works for Perl5.8 in the csh shell ...that would be great. ****************** ... (3 Replies)
Discussion started by: andy b
3 Replies

5. Shell Programming and Scripting

HELP WITH SEARCH AND SUBSTITUTE IN "|" DELIMITED FILE

Hi I have a "|" delimited file as shown below. 55987|2011-04-07|09:30: 8.0|09:30:27.4|9194 55988|2011-04 07|09:30:21.0|09:30:27.4|9199 55989|2011-04-07|09:30:25.0|09:30:27.5|9176 55990|2011-04-07|09:29:33.0|09:30:27.5|9196 55991|2011-04-07|09:30:21.0|09:30:27.5|9199... (3 Replies)
Discussion started by: alok3141
3 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. UNIX for Advanced & Expert Users

Flat file "database"

I'm wondering about the best way to store large amounts of sorted data, sorted by date/time, in a manner to allow fast retrieval of ranges of dates. Deletion isn't necessary. A database hardly seems ideal, since they're not optimized for sorted data, and allow things I don't need like the... (18 Replies)
Discussion started by: Corona688
18 Replies

8. Shell Programming and Scripting

Not able to create any file name start with "-" hyphen in Solaris

Hi All, I am not able to create any file name start with "-" hyphen. Any logical issue with these types of files creation in Solaris. ============================== bash-3.00$ touch -file.txt touch: illegal option -- i usage: touch file... touch ] file... touch ... (5 Replies)
Discussion started by: hanu_oracle
5 Replies

9. HP-UX

To give the "unzip" permissions & "create" file permissions

Hi, I am a Unix Admin. I have to give the permissions to a user for creating new file in a directory in HP-Ux 11.11 system since he cannot able to create a new file in the directory. Thanks in advance. Mike (3 Replies)
Discussion started by: Mike1234
3 Replies
Login or Register to Ask a Question