Sponsored Content
Full Discussion: awk+MySQL
Top Forums Shell Programming and Scripting awk+MySQL Post 302226689 by Locki on Tuesday 19th of August 2008 03:17:52 PM
Old 08-19-2008
I think my code produced what you want but not what MySQL is expecting when there blanks within the fields. If MySQL accept compound-strings surrounded by "double quote" cars. In that case, you should use

Code:
sed -e '1,4d' -e 's/[ ]*|[ ]*/|/g' -e "s/^|//" -e "s/|$//" pet_1.txt | awk -F "|" '\
{ \
  s = ""; \
  for( i = 1; i <= NF; i++) { \
    if ($i == "NULL") $i = "\\N"; \
\
    p = match($i,"[ ]"); \
    if ( p != 0 ) $i = sprintf("\"%s\"", $i); \
\
    if (s == "" ) s = $i; \
    else s = sprintf("%s\t%s", s, $i); \
  } \
  print s; }' > new_pet.txt

sudhamacs, clever solution but :
  1. if a field has "NULL" in it (as in "this is a NULL case"), it won't work (I agree, it's rather a stupid case Smilie )
  2. the 4 first lines of the header are still there
  3. your method adds a \t at the begining of the record ... don't know if it is accepted Smilie

Last edited by Locki; 08-19-2008 at 04:26 PM..
 

6 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: amon
3 Replies

4. 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

5. 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

6. 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
SQL::ReservedWords::MySQL(3pm)				User Contributed Perl Documentation			    SQL::ReservedWords::MySQL(3pm)

NAME
SQL::ReservedWords::MySQL - Reserved SQL words by MySQL SYNOPSIS
if ( SQL::ReservedWords::MySQL->is_reserved( $word ) ) { print "$word is a reserved MySQL word!"; } DESCRIPTION
Determine if words are reserved by MySQL. METHODS
is_reserved( $word ) Returns a boolean indicating if $word is reserved by either MySQL 3.2, 4.0, 4.1, 5.0 or 5.1. is_reserved_by_mysql3( $word ) Returns a boolean indicating if $word is reserved by MySQL 3.2. is_reserved_by_mysql4( $word ) Returns a boolean indicating if $word is reserved by either MySQL 4.0 or 4.1. is_reserved_by_mysql5( $word ) Returns a boolean indicating if $word is reserved by either MySQL 5.0 or 5.1. reserved_by( $word ) Returns a list with MySQL versions that reserves $word. words Returns a list with all reserved words. EXPORTS
Nothing by default. Following subroutines can be exported: is_reserved is_reserved_by_mysql3 is_reserved_by_mysql4 is_reserved_by_mysql5 reserved_by words SEE ALSO
SQL::ReservedWords <http://dev.mysql.com/doc/> AUTHOR
Christian Hansen "chansen@cpan.org" COPYRIGHT
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.8.8 2008-03-28 SQL::ReservedWords::MySQL(3pm)
All times are GMT -4. The time now is 10:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy