feeding a series of input args to a command that only takes one

This is a discussion on feeding a series of input args to a command that only takes one within the Linux General forums, part of the Linux Forums category; Icarus Sparry <usenet@icarus.freeuk.com> wrote in news:481ab188$0$34548 $742ec2ed@news.sonic.net: > > ...


Go Back   Usenet Forums > Linux Forums > Linux General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 05-02-2008
Rahul
 
Posts: n/a
Default Re: feeding a series of input args to a command that only takes one

Icarus Sparry <usenet@icarus.freeuk.com> wrote in news:481ab188$0$34548
$742ec2ed@news.sonic.net:

>
> cmd1 | cmd2 | while read ip ; do ip2hex $ip ; done


Thanks guys for all those leads! I think xargs works perfect. Does my
job. Just out of curiosity though: I haven't been able to hack together
the while read oneliner that would do the same job:

echo "11.0.0.1 \n 11.0.0.2 \n 11.0.0.3" | while read ip ; do ip2hex $ip
; done

Only does the first address. Even tried:

echo "11.0.0.1 11.0.0.2 11.0.0.3" | while read ip ; do ip2hex $ip ;
done

What's the correct form?

--
Rahul
Reply With Quote
  #12 (permalink)  
Old 05-02-2008
Kees Theunissen
 
Posts: n/a
Default Re: feeding a series of input args to a command that only takes one

Rahul wrote:
> Icarus Sparry <usenet@icarus.freeuk.com> wrote in news:481ab188$0$34548
> $742ec2ed@news.sonic.net:
>
>> cmd1 | cmd2 | while read ip ; do ip2hex $ip ; done

>
> Thanks guys for all those leads! I think xargs works perfect. Does my
> job. Just out of curiosity though: I haven't been able to hack together
> the while read oneliner that would do the same job:
>
> echo "11.0.0.1 \n 11.0.0.2 \n 11.0.0.3" | while read ip ; do ip2hex $ip
> ; done
>
> Only does the first address. Even tried:
>
> echo "11.0.0.1 11.0.0.2 11.0.0.3" | while read ip ; do ip2hex $ip ;
> done
>
> What's the correct form?


Supply only one IP number per line. The "read" command will read a
complete line on each invocation.

Compare:
kees@lankhmar:~$ echo "11.0.0.1 \n 11.0.0.2 \n 11.0.0.3"
11.0.0.1 \n 11.0.0.2 \n 11.0.0.3
with:
kees@lankhmar:~$ echo -e "11.0.0.1 \n 11.0.0.2 \n 11.0.0.3"
11.0.0.1
11.0.0.2
11.0.0.3


Regards,

Kees.

--
Kees Theunissen.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0