Re: [CentOS] xargs with max each line / argument
On 5/17/11 12:36 AM, neubyr wrote: How do I pass xargs input one line at a time to subsequent command? For example I want to install rubygems by reading a text file as shown below, however the arguments are getting passed all at once to the 'gem install' command. I hace tried -L (max-lines) and -n (max args) options, but it didn't work. What's missing here?? Any help? $ cat gem.list.1 mkrf rake xmlparser $ awk '{ print $0 }' gem.list.1 | xargs -L 1 -0 -I name sudo gem install name ERROR: could not find gem mkrf rake xmlparser locally or in a repository Or: cat gem.list.1 | while read PKG; do sudo gem install $PKG; done JD ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] xargs with max each line / argument
On Tue, May 17, 2011 at 12:36:08AM -0500, neubyr wrote: How do I pass xargs input one line at a time to subsequent command? xargs is the wrong tool for this job. $ awk '{ print $0 }' gem.list.1 | xargs -L 1 -0 -I name sudo gem install name while read line do sudo gem install $line done gem.list.1 -- rgds Stephen ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] xargs with max each line / argument
-Original Message- From: centos-boun...@centos.org [mailto:centos-boun...@centos.org] On Behalf Of neubyr Sent: 17/05/2011 06:36 To: CentOS mailing list Subject: [CentOS] xargs with max each line / argument How do I pass xargs input one line at a time to subsequent command? For example I want to install rubygems by reading a text file as shown below, however the arguments are getting passed all at once to the 'gem install' command. I hace tried -L (max-lines) and -n (max args) options, but it didn't work. What's missing here?? Any help? $ cat gem.list.1 mkrf rake xmlparser $ awk '{ print $0 }' gem.list.1 | xargs -L 1 -0 -I name sudo gem install name ERROR: could not find gem mkrf rake xmlparser locally or in a repository thanks, neuby.r Hi. As others have mentioned, a simple cat or use of into xargs will simplify things. The max-args switch _is_ the one you are looking for: --max-args=max-args, -n max-args Spceifically: cat gem.list.1 | xargs --max-args=1 sudo gem install will do what you want, I think - please test it first. You could add --interactive to xargs to help with this, or even just: cat gem.list.1 | xargs --max-args=1 echo sudo gem install which will just dump the commands that would be run (using echo). hth Andy ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] xargs with max each line / argument
Andy Holt wrote: [mailto:centos-boun...@centos.org] On Behalf Of neubyr How do I pass xargs input one line at a time to subsequent command? For example I want to install rubygems by reading a text file as shown below, however the arguments are getting passed all at once to the 'gem install' command. I hace tried -L (max-lines) and -n (max args) options, but it didn't work. What's missing here?? Any help? $ cat gem.list.1 mkrf rake xmlparser $ awk '{ print $0 }' gem.list.1 | xargs -L 1 -0 -I name sudo gem install name ERROR: could not find gem mkrf rake xmlparser locally or in a repository snip Screw xargs. Read an awk tutorial, maybe. Learn your tools. awk '{name = $1; cmd = sudo gem install name; system( cmd);}' gem.list.1. mark yes, I do do awk... ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] xargs with max each line / argument
Thanks for the help everyone. I used awk as the gem.list file may contain version number in brackets - rake (1.2). I should have mentioned this before. I used 'awk $1' to get first column from each row. I liked all inputs, but I think I will try mark's awk solution here. Thanks again.. On Tue, May 17, 2011 at 8:30 AM, m.r...@5-cent.us wrote: Andy Holt wrote: [mailto:centos-boun...@centos.org] On Behalf Of neubyr How do I pass xargs input one line at a time to subsequent command? For example I want to install rubygems by reading a text file as shown below, however the arguments are getting passed all at once to the 'gem install' command. I hace tried -L (max-lines) and -n (max args) options, but it didn't work. What's missing here?? Any help? $ cat gem.list.1 mkrf rake xmlparser $ awk '{ print $0 }' gem.list.1 | xargs -L 1 -0 -I name sudo gem install name ERROR: could not find gem mkrf rake xmlparser locally or in a repository snip Screw xargs. Read an awk tutorial, maybe. Learn your tools. awk '{name = $1; cmd = sudo gem install name; system( cmd);}' gem.list.1. mark yes, I do do awk... ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
[CentOS] xargs with max each line / argument
How do I pass xargs input one line at a time to subsequent command? For example I want to install rubygems by reading a text file as shown below, however the arguments are getting passed all at once to the 'gem install' command. I hace tried -L (max-lines) and -n (max args) options, but it didn't work. What's missing here?? Any help? $ cat gem.list.1 mkrf rake xmlparser $ awk '{ print $0 }' gem.list.1 | xargs -L 1 -0 -I name sudo gem install name ERROR: could not find gem mkrf rake xmlparser locally or in a repository thanks, neuby.r ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] xargs with max each line / argument
On 5/17/11 12:36 AM, neubyr wrote: How do I pass xargs input one line at a time to subsequent command? For example I want to install rubygems by reading a text file as shown below, however the arguments are getting passed all at once to the 'gem install' command. I hace tried -L (max-lines) and -n (max args) options, but it didn't work. What's missing here?? Any help? $ cat gem.list.1 mkrf rake xmlparser $ awk '{ print $0 }' gem.list.1 | xargs -L 1 -0 -I name sudo gem install name ERROR: could not find gem mkrf rake xmlparser locally or in a repository The -0 to xargs says your items will be null-terminated, but they aren't. And you don't really need awk to pick the first field out of a one-field line, just cat it or let xargs read it directly with gem.list.1 -- Les Mikesell lesmikes...@gmail.com ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos