awk and mysql

Helloo,

I have worked with some files and so far I got to to point there I have a

fileA:

Person1_Operation20060611090814
Person4_Operation20060512090811
Person6_Operation20060613090214
Person2_Operation20060115090815
Person9_Operation20060617100814
..
...
...

so I was thinking is there a way to create file like this:

Date|Time|Person|Operation
20060611|090814|Person1|Operation
20060611|090811|Person4|Operation
20060613|090214|Person6|Operation
20060115|090815|Person2|Operation
20060617|100814|Person9|Operation

I was trying to to something with awk but it was useless..

Any help??

Also I have one more Q. I have mysql database on other Windows machine..
is there a way or how can I do that to conect to Mysql with shell script and do insert by shell script??

cherrs

This really depends on your input data ... is it all in fixed lenght fields as is sort of suggested by your example?

For exmple:

 awk '{printf("%s|%s|%s|%s\n",substr($0,18,8),substr($0,24,6),substr($0,0,7),substr($0,9,9));}' data.txt

Turns your given input data into your required output data ... but it almost certinaly wont work on all the input data you have ...

EDIT: some numbers in the substrings were wrong

Thanks...:slight_smile:
of course just little edit on substr. but perfect..also I tryed to do this with cut command..and here what I tryed but it won't pass..

cut -f 1-6,8-24,25-32,25-32,33-38 -d '|' file1 > file2

of course mayve columns are not right one but I get on file2 exact a same file as file1...

any adeas about mysql topic??

But thank U Unbeliever that worked perfect :wink:

If you install the same basic version of mysql on your unix machine as is running on your windows machine you can use the mysql client commands to connect to the remote windows installation (you dont need to start the database).

mysql -u <user> -h <hostname> -p <databasename>

is the basic structure. Where <hostname> is the name (or IP address) of the windows machine on which your existin database is running.

Reading the manual is best of course :slight_smile: