Re: Sed, awk? [solved]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin brings up the best point.  You should fit your program to read from a
file or pipe instead of from an argument list.  Much more flexible that way
:)


Jake, in response to your "Number 2 worked" but you still could'nt get it
into one line and had to cut and paste after your spam.spam account,

replace "echo -n" with the spam.spam.  xargs basically takes STDIN and puts
it all on one command line.  That's what it does.

anyway, try this out when you have time:
grep 'alsdfj' * | awk -F: '{print $1}' | uniq | xargs spam.spam  (replace
"echo -n" with spam.spam)

I started using xargs with "find" instead of exec because I read somewhere
at one item that when you use "exec" with find it spawns off a process for
each exec. If you wanted to keep your "exec" to one process, then to use
xargs.  I don't know, something like that :)  I don't know if that's still
true and I never bothered verifying it.  I just know it's more intuitive for
me to use a pipe and xargs then using exec rm () or exec rm {} or whatever
the syntax is.  And it's a habit now

I encourage people unfamiliar with xargs to  experiment around a bit with
it, especially with find.  Good sysadmin tool/trick to do recursive file
manipulation , and to me "find . -print" much cleaner looking than "ls -R"

e.g. recursive file size finder
find . -type f -print | xargs ls -s
find . -type f -print | xargs du -sk


e.g. tar specific files together
find . -type f -name "*.conf" -print | xargs tar cpvf /tmp/conffiles.tar

cheers
Ben Y




== Original email below ===
Replying to my own post... *grin*

Martin Stricker wrote:
>
> Jake McHenry wrote:

> >   grep 'nittany' * | cut -f 1 -d : | tr \\012 \\40 | spam.spam

> >   spam.spam | grep 'nittany' * | cut -f 1 -d : | tr \\012 \\40

> So try
> spam.spam ` grep -R 'email' * | awk -F: '{print $1}' | uniq | xargs \
> echo -n `
> (the backslash \ makes this work with the line break, if you issue it
> on one line, just omit it) and
> spam.spam ` grep 'nittany' * | cut -f 1 -d : | tr \\012 \\40 `

Note that the length of the argument list is limited (unless you build a
custom kernel, on Red Hat Linux you may not have more than 1024
arguments in the line, or is it 1024 characters?). The length of a pipe,
however, is not limited (I have piped complete ISO CD images through
pipes). So you should try to rewrite your script so it reads from the
standard input instead of using an argument list. With xargs you can get
around the "argument list too long" error message, but as I understand
you are writing to a file, and that might get you into trouble.

Best regards,
Martin Stricker


-- 
Shrike-list mailing list
Shrike-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/shrike-list

[Index of Archives]     [Fedora Users]     [Centos Users]     [Kernel Development]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat Phoebe Beta]     [Yosemite Forum]     [Fedora Discussion]     [Gimp]     [Stuff]     [Yosemite News]

  Powered by Linux