Re: Sed, awk?

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

 



Jake McHenry wrote:

Thanks! Would there be a way to get them all on one line instead of
many, seperated by a space for input to another command? Being they
are all on their own lines, it's kind of messy for input to another
command.


echo $(oneliner | grep 'whatever' | cut -f1 -d:)
or
echo $(oneliner | awk -F: '/whatever/' {print $1}')
or
echo $(oneliner | sed -n '/whatever/s/:.*//p')
or
echo $(oneliner | perl -ne 'if (/whatever) {split(/:/); print @_[0] . "\n"}')
or
echo $(for i in $(oneliner | grep '/whatever/'); do echo "${i%:*}"; done)


(This last one has problems when "oneliner" produces lines that match the RE that contain spaces, but that's fixable.)


Replace "echo" with the command of your choice.


How many different ways would you like? This is Unix :-) I got bored thinking up different ways.


Actually, I've just noticed you said:


oneliner | grep 'whatever' *

In this case grep looks for whatever in all the files in the current directory. What's the purpose of "oneliner"? Or is the "*" an oversight.

jch





--
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