LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-28-2008, 11:35 AM   #1
kcorkran
LQ Newbie
 
Registered: Jan 2008
Location: Austin, TX
Distribution: Suse
Posts: 6

Rep: Reputation: 0
sed parsing into sql statement


Hello Everyone:

I have pretty much exhausted my time line on this project:
I am using cygwin to do this:

I need to parse this text line into this sql statement:
this:
08/14/2002 09:38 AM 538,131 10.jpg

into this:
UPDATE dbo.tblName SET intMapFIleSizeBytes = 538131,
txtMapExists = 'Y',
datMapFileDirDate = '08/14/2002 09:38 AM'
WHERE txtMapFileName = '10.jpg'
go

Any help appreciated:

Thanks,
Keith
 
Old 02-28-2008, 11:43 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
well it depends quite what the input always is. going on each of those spaces being a single one and always being there...

date=$(echo $string | cur -d\ -f -3)
size=$(echo $string | cur -d\ -f 4 | tr -d ',')
name=$(echo $string | cur -d\ -f 5)

and then just drop those variables into the sql string:

echo UPDATE dbo.tblName SET intMapFIleSizeBytes = $size, txtMapExists = \'Y\', datMapFileDirDate = \'$date\' WHERE txtMapFileName = \'$name\'

etc...
 
Old 02-28-2008, 12:34 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Or in awk :}
Code:
{
  print "UPDATE dbo.tblName"
  print "SET intMapFIleSizeBytes = "gensub( /,/ , "", "g", $4)","
  print "    txtMapExists = 'Y',"
  print "    datMapFileDirDate = '"$1" "$2" "$3"'"
  print "WHERE txtMapFileName = '"$5"'"
  print "go"
}
Run like:
Code:
$ echo "08/14/2002 09:38 AM 538,131 10.jpg" | awk -f sql.awk
UPDATE dbo.tblName
SET intMapFIleSizeBytes = 538131,
    txtMapExists = 'Y',
    datMapFileDirDate = '08/14/2002 09:38 AM'
WHERE txtMapFileName = '10.jpg'
go



Cheers,
Tink
 
Old 02-28-2008, 04:43 PM   #4
kcorkran
LQ Newbie
 
Registered: Jan 2008
Location: Austin, TX
Distribution: Suse
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks Y'all!

That is going to do it...

I promise to apply myself to learning these scripting techniques more in the future...

-Keith
 
Old 02-28-2008, 07:01 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,412

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Errr, acid_kewpie I assume you mean 'cut' not 'cur' ?
Could confuse the poor guy...
 
Old 02-29-2008, 04:04 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
oh crap. yeah. my keyboard is clearly too small.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL statement to get the last row in a table oulevon Programming 11 04-03-2009 09:30 PM
help optimizing this SQL statement hedpe Programming 1 05-30-2007 08:06 AM
help with simple sql statement sekelsenmat Programming 6 08-06-2005 01:01 PM
mysql sql statement help mrtwice Programming 4 12-02-2003 11:04 AM
SQL statement glj Programming 1 10-12-2001 10:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration