The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to print single quote in awk gauravgoel UNIX for Dummies Questions & Answers 6 08-20-2008 04:48 PM
escaping single quote javeed7 Shell Programming and Scripting 3 04-02-2008 05:36 AM
single quote dreams5617 Shell Programming and Scripting 2 12-01-2007 03:37 AM
single or double quote in SED asami Shell Programming and Scripting 2 07-17-2006 03:03 AM
Replacing a single quote rjsha1 Shell Programming and Scripting 3 12-23-2005 10:55 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-27-2006
braindrain braindrain is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 67
AWK handling of single quote

Hi,
Can someone let me know how I can acheive the following.

I have ~ delimited file and I need to convert into something like SQL insert statements.

SrcFile :
1~sjdsdj~asasas~
2~aaaaa~qwqwqwq~qwq
.....

I tried
Code:
AWK -F"~" '{print "INSERT INTO XX VALUES("$1 " ,\' "$2" \' , \' "$3 }' SrcFile
However AWK always treat '(single quote) as differently & i guess since single quote appear more than once. Any idea how i can make awk to treat single quote as text character or is this possible in SED?



'{print "INSERT INTO XX VALUES("$1 " ,\' "$2" \' , \' "$3 }'
|------------------------------------|xxxxxxx|--|xxxxxx|
  #2 (permalink)  
Old 04-27-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
sqlldr will handle this for you - it looks like you're using Oracle.
Code:
OPTIONS (DIRECT=false)
LOAD DATA
INFILE 'myfile'
APPEND
INTO TABLE MYTABLE
FIELDS TERMINATED BY '~'
TRAILING NULLCOLS
(FLD1, FLD2, FLD3)
a ctl file like this one will do what you show.
  #3 (permalink)  
Old 04-27-2006
braindrain braindrain is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 67
Hi Jim,
Sure, this will work, Infact my stop gap approach is this. However we are looking to acheive this in shell scripting, as we gonna apply this to disparate databases.

thx
  #4 (permalink)  
Old 04-27-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
nawk -F"~" -v q="'" '{print "INSERT INTO XX VALUES("$1 " ," q "$2" q "," q $3 }' SrcFile
you'll have to figure out the ballancing of the double-quotes inside the 'print' - I think I got it right, but......
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0