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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
xargs problem encrypted Shell Programming and Scripting 3 05-16-2009 12:15 PM
Question concerning xargs cp27316 UNIX for Dummies Questions & Answers 4 03-13-2007 11:30 PM
xargs doubt shihabvk Shell Programming and Scripting 1 09-29-2005 10:38 AM
find | xargs cat asal_email Shell Programming and Scripting 4 03-17-2005 12:16 AM
Help with xargs JimJim UNIX for Dummies Questions & Answers 4 02-08-2005 07:08 PM

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 09-16-2001
jpprial jpprial is offline
Registered User
  
 

Join Date: Feb 2001
Location: San Francisco
Posts: 30
xargs

Can I use xargs to send a list of commands to a process, to be acted upon individually? Here's what I have: a file that contains numbers, one per line. The desired outcome it to send each number to a DB2 query. I thought xargs would work, but it doesn't. I tried it like this:

cat file | xargs | db2 "select * from table where field = $*"

Can this work somehow?

thanks
  #2 (permalink)  
Old 09-16-2001
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,661
Someone else can reply better than I concerning xargs because I rarely use that utility.

FWIW: if I had your problem I would write a 5 line PERL script that:

(1) opens the file
(2) reads each line into a $variable
(3) executes the DB command with $variable.

You can also do this with other shell languages using the same basic idea/algorithm above.

Someone familar with PERL , for example, could write the script faster than it takes to post to the forum because it is just a few lines of code.

Others may want to discuss your xarg problem-solution more directly......


can you believe it?? ...... i was just making a peanut-butter-and-jelly sand' and dropped a big hunk of peanut butter on the keyboard replying to this post ....
  #3 (permalink)  
Old 09-17-2001
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
xargs would not be my first choice for something like this, but it can certainly be made work. I don't know what the db command is and looking at your syntax, I can't tell where the arg should be inserted, but here is an example using echo:

cat file | xargs -l -i echo "arg is {}"

and even better:

xargs -l -i echo "arg is {}" < file

Hmmm, I gotta admit that using xargs in a case like this is starting to appeal to me...
  #4 (permalink)  
Old 09-17-2001
jpprial jpprial is offline
Registered User
  
 

Join Date: Feb 2001
Location: San Francisco
Posts: 30
xargs works

Thanks everyone. I did get it to work, using xargs with the -n1
option.

file1 is just a list of numbers, one per line:
1234455
7778889



cat file1 | xargs -n1 "db2 select * from table1 where field1 in ('$*')"
  #5 (permalink)  
Old 09-17-2001
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,661
Nice job. Thanks for the follow-up post with your solution for everyone interested in xargs to learn from.
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 09:50 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