Sos Sos


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sos Sos
# 1  
Old 10-04-2005
Network Sos Sos

INPUT---> USER | User1 | DisplayName1 | HomeTown1 | 987654321 | 27-07-1991 | M

i want to separate out all the fields of the file which has the format specified above , with the use of awk. I was writing that to the mysql by batch-file. But now there is problem , in databse i have defined the the datatype date for storing the date (2nd last field from the raw file) ,and format of the date is exactly opposite of that of dd-mm-yyyy ie,. yyyy-mm-dd.

So please help me to extract the field with correct date format (yyyy-mm-dd).or in short out put will this for the above given input. Smilie

output-> insert into XYZ values("user1","DisplayName1","HomeTown","987654321","1991-07-27","m");
# 2  
Old 10-04-2005
Try this...
Code:
awk 'BEGIN{FS=" \\| "}
 { printf "insert into XYZ values(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\");\n",\
           $2, $3, $4, $5, substr($6,7) "-" substr($6, 4,2) "-" substr($6,1,2), $7
 }' file1 > file2

I did test it...
Code:
$ head file[12]
==> file1 <==
USER | User1 | DisplayName1 | HomeTown1 | 987654321 | 27-07-1991 | M

==> file2 <==
insert into XYZ values("User1","DisplayName1","HomeTown1","987654321","1991-07-27","M");

# 3  
Old 10-05-2005
Thank you

great ! ygor
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. HP-UX

sos about swpackage AND swinstall

hi all, I just want to make a depot package.All steps: 1. make a psf file # PSF which define the myutil product depot layout_version 1.0 tag ddmi_linux_installer title ddmi_linux_installer # Product definition vendor tag HP title Hewlett-Packard Company product tag... (0 Replies)
Discussion started by: lb1111830
0 Replies

2. Solaris

file not found (SOS)

Hi, friends, I am new here and also new in Unix. I want your kindly help for now! I cannot run the program vmed on my computer ,that reply the error $ vmed bash: vmed: command not found $ ./vmed ld.so.1: vmed: fatal: libpgplot.so: open failed: No such file or directory Killed as I... (12 Replies)
Discussion started by: wholesome80
12 Replies

3. Shell Programming and Scripting

SOS whit SED

Hello, I know how to get a solution of a filtering problem with AWK, but i need change default field separator by a regular expression. awk -F "xxx" What i want to do is take a stranza as a field, so the field separator must be a EMPTY line. Does anybody how to do that?? a example: ... (1 Reply)
Discussion started by: antuan
1 Replies

4. Solaris

sun connect :SOS

hi all, does someone have any information about "sun connect" (like documentation , web site , forums , explanations .....) ? because i will need this software in my job & i don't know how to use it :o (4 Replies)
Discussion started by: lid-j-one
4 Replies

5. Shell Programming and Scripting

Sos

Dear "expert", I need to know the command syntax to get the last field of the line below using shell or awk. MD5... (4 Replies)
Discussion started by: Lee Soon Yau
4 Replies

6. UNIX for Dummies Questions & Answers

[sos]How to resure my system.

Yesterday,I have a unnormal shutdown of my SCO Unix system,when I boot again,There are lots of Errors (e.g policy manager error, ifor_pmd error etc.),Most seriously,I can use my "CC" compiler: when I compile my *.c files. Who Can Help Me ! Please Don't spare your instructions! Thanks a... (5 Replies)
Discussion started by: dingxf
5 Replies

7. UNIX for Dummies Questions & Answers

(SOS) Please help !

Does anybody can help me with the definition of "terminal" DTE and DCE in context to Unix ?. This has something to do with devices in Unix. I need it asap. Thank you very much !:confused: (1 Reply)
Discussion started by: aqua_jan
1 Replies
Login or Register to Ask a Question