The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
MySQL article - Sun and MySQL: How It Stacks Up for Developers iBot UNIX and Linux RSS News 0 02-28-2008 08:20 PM
MySQL conflicts with mysql-3.23.58-16.RHEL3.1 johnveslin Linux 2 07-17-2007 03:49 AM
mysql would not start: missing mysql.sock xnightcrawl UNIX for Advanced & Expert Users 2 05-26-2006 07:06 AM
PHP and MySQL kwalick UNIX for Dummies Questions & Answers 2 04-23-2004 07:13 AM
MySQL problem >> missing mysql.sock _hp_ UNIX for Advanced & Expert Users 8 11-03-2002 11:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-14-2006
Registered User
 

Join Date: Jan 2006
Posts: 71
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
Reply With Quote
Forum Sponsor
  #2  
Old 06-14-2006
Registered User
 

Join Date: Jul 2005
Location: England
Posts: 183
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 07:46 AM.
Reply With Quote
  #3  
Old 06-14-2006
Registered User
 

Join Date: Jan 2006
Posts: 71
Thanks...
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
Reply With Quote
  #4  
Old 06-15-2006
Registered User
 

Join Date: Jul 2005
Location: England
Posts: 183
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 :-)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0