[clug] Two (perhaps simple) shell questions.

Mark Triggs mark at dishevelled.net
Tue Aug 18 05:20:50 MDT 2009


Andrew Janke <a.janke at gmail.com> writes:

> On Tue, Aug 18, 2009 at 11:39, Mark Triggs<mark at dishevelled.net> wrote:
>
>>> for i in `ls *.mnc`;
>>> do
>>>    do8ofthisatonce <program> $i $i.out
>>> done
>>
>> xargs will do this for you.  Something like:
>>  ls *.mnc | xargs -I'{}' -P 8 program {} {}.out
>
> Thanks Mark, I knew that one day I should learn xargs.. ;)  Still
> while this will work in most of the things I do xargs doesn't seem to
> allow multiple commands?  ie (for arguments sake):
>
> for i in `ls *.mnc`;
>  do
>     var=`basename $i`
>     do8ofthisatonce <program> $var $i.out
>  done
>
> If the answer is "can't be done" then so be it. :)  I guess in this
> case I could make a quick shell script and call that using xargs but
> that sort of spoils the fun.

Hm, you could cheat at this point by constructing your own command line:

  /bin/ls *.mnc | xargs -I'{}' -P8 sh -c "echo `basename {}` {}.out"


> PS: perl -pe 'chop if !($. % 2)' < myfile   (yes only one less
> character but it seemed an obvious start).

Drat!  I never was good at golf.  I suppose I could continue the trend
with:

  perl -pe 'chop if!($.%2)' < myfile

-- 
Mark Triggs
<mark at dishevelled.net>


More information about the linux mailing list