Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Extract a f...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 7 Topic 2184 of 2297
Post > Topic >>

Re: Extract a field in a string collection

by Ed Morton <morton@[EMAIL PROTECTED] > Mar 11, 2008 at 12:20 AM

On 3/10/2008 7:26 PM, Tiago Peczenyj wrote:
> On 10 mar, 21:20, Radu <raduco...@[EMAIL PROTECTED]
> wrote:
> 
>>Hi guys,
>>
>>From a .csv file, I want to extract the last field (say it's $15, or,
>>I guess, $NF) and make it like:
>>'12345', '23456', '34567' (comma separated strings).
>>The purpose is to use the list in a select request in the WHERE clause
>>(WHERE field IN ('12345', '23456', '34567').
>>The IN range would be therefore the file the AWK will sent the values
>>to.
>>
>>Thanks,
>>
>>Radu
> 
> 
> try a awk file like this:
> BEGIN{ printf("(WHERE field in ("); }
> { printf("'%s'",$NF); }
> END{ printf(")"); }

printf is a language construct, not a function, so all those spurious
brackets
are misleading at best. You also have some redundant semi-colons, are
missing
the final newline, and are missing the comma followed by a space between
each
entry in the output list. This would solve those problems:

BEGIN{ printf "(WHERE field in (" }
{ printf "%s'%s'",sep,$NF; sep=", " }
END{ print ")" }

Since the OP didn't provide any sample input, I'm not sure that's the
right
solution though...

	Ed.
 




 7 Posts in Topic:
Extract a field in a string collection
Radu <raducocos@[EMAIL  2008-03-10 17:20:34 
Re: Extract a field in a string collection
Tiago Peczenyj <tiago.  2008-03-10 17:26:33 
Re: Extract a field in a string collection
Ed Morton <morton@[EMA  2008-03-11 00:20:35 
Re: Extract a field in a string collection
"Scott S. McCoy"  2008-03-11 00:46:42 
Re: Extract a field in a string collection
Ed Morton <morton@[EMA  2008-03-11 00:29:04 
Re: Extract a field in a string collection
"Scott S. McCoy"  2008-03-11 00:49:14 
Re: Extract a field in a string collection
Ed Morton <morton@[EMA  2008-03-10 21:24:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 20:33:30 CDT 2008.