xargs question
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > xargs question




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    xargs question  
RolandRB


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-14-07 12:20 PM

I want to run "cmp" on a batch of files that fits a file pattern but I
want the return code to be displayed at the end of "cmp" processing. Is
this possible just using "xargs" as in the example below? I have tried
"cmp {} txtdir/{} ; echo \$?" but it gives a syntax error.

$ ls -1 r*.txt | xargs -t -I {} cmp {} txtdir/{}
cmp roland.txt txtdir/roland.txt
cmp roland2.txt txtdir/roland2.txt
roland2.txt txtdir/roland2.txt differ: char 1, line 1
cmp roland3.txt txtdir/roland3.txt






[ Post a follow-up to this message ]



    Re: xargs question  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-14-07 12:20 PM

2007-01-14, 01:42(-08), RolandRB:
> I want to run "cmp" on a batch of files that fits a file pattern but I
> want the return code to be displayed at the end of "cmp" processing. Is
> this possible just using "xargs" as in the example below? I have tried
> "cmp {} txtdir/{} ; echo \$?" but it gives a syntax error.
>
> $ ls -1 r*.txt | xargs -t -I {} cmp {} txtdir/{}
> cmp roland.txt txtdir/roland.txt
> cmp roland2.txt txtdir/roland2.txt
> roland2.txt txtdir/roland2.txt differ: char 1, line 1
> cmp roland3.txt txtdir/roland3.txt

You cmp may have a verbose option.

Otherwise, you'd have to have xargs call sh, so best it to do
the whole thing with the shell:

(
set -x
for f in r*.txt; do
cmp "$f" "txtdir/$f"; echo "$?"
done
)

--
Stéphane





[ Post a follow-up to this message ]



    Re: xargs question  
RolandRB


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-20-07 12:23 PM


Stephane CHAZELAS wrote:
> 2007-01-14, 01:42(-08), RolandRB: 
>
> You cmp may have a verbose option.
>
> Otherwise, you'd have to have xargs call sh, so best it to do
> the whole thing with the shell:
>
> (
>   set -x
>   for f in r*.txt; do
>     cmp "$f" "txtdir/$f"; echo "$?"
>   done
> )
>
> --
> St=E9phane

Thanks for that. What I did in the end is write a little script named
"cmprc" ("cmp" with return code) so that I could use xargs to call it
like this.

ls -1 r*.txt | xargs -I {} cmprc {} txtdir/{}

"cmprc" echoes the return code as well as the command.

http://www.datasavantconsulting.com...e/scripts/cmprc






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:59 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register