awk and mysql


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk and mysql
# 1  
Old 06-14-2006
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
# 2  
Old 06-14-2006
This really depends on your input data ... is it all in fixed lenght fields as is sort of suggested by your example?

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

Last edited by Unbeliever; 06-14-2006 at 11:46 AM..
# 3  
Old 06-15-2006
Thanks...Smilie
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 Smilie
# 4  
Old 06-15-2006
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).

Code:
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 :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk cmd for vlookup in Mysql

Hi, Is there possible to do vlookup in Mysql one table from another table based on one column values and placed the data in same table? if it is possible in mysql itself pls share links for reference. Here is the ex: i need to vlookup the cus.id in table to and place the cus.name in 4th... (3 Replies)
Discussion started by: Shenbaga.d
3 Replies

2. Shell Programming and Scripting

Help: Change date to datetime mysql using awk

#cat file1.log 10.51.61.38;Thu Nov 1 08:06:12 2012;Logout 10.51.62.21;Thu Nov 1 08:06:16 2012;Login output result: 10.51.61.38;2012-11-01 08:06:12;Logout 10.51.62.21;2012-11-01 08:06:16;Login how to write script using awk, need help (1 Reply)
Discussion started by: pillawa
1 Replies

3. UNIX and Linux Applications

MySQL Daemon failed to start - no mysql.sock file

After doing a yum install mysql mysql-server on Fedora 14 I wasn't able to fully install the packages correctly. It installed MySQL 5.1. I was getting the following error when running the: mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)... (3 Replies)
Discussion started by: jastanle84
3 Replies

4. Shell Programming and Scripting

awk+MySQL

Hi everyone, I have a large text file that is output of mysql select, like: pet: +--------------+-------------+---------+------+------------+ | name | owner | species | sex | birth | +--------------+-------------+---------+------+------------+ | Mickey Mouse | Walt Disney... (7 Replies)
Discussion started by: tibibo
7 Replies

5. UNIX for Advanced & Expert Users

mysql would not start: missing mysql.sock

I recently installed mysql-standard-5.0.21-solaris9-sparc-64bit.pkg on a Solaris 9 machine (SunOS 5.9 Generic_118558-19 sun4u sparc SUNW,Ultra-250). The package installation went very smooth, however, starting mysql is a different story. I get the message below everytime I try to start mysql: #... (2 Replies)
Discussion started by: xnightcrawl
2 Replies

6. UNIX for Advanced & Expert Users

MySQL problem >> missing mysql.sock

MySQL on my server is down.... I figured out that the mysqld process isn't running. When I try to run it, it says it can't find mysql.sock Any suggestions? Here's what I can't do: can't be root don't have physical access (do stuff via SSH) reinstall MySQL (need to keep the current MySQL... (8 Replies)
Discussion started by: _hp_
8 Replies
Login or Register to Ask a Question