[NTLUG:Discuss] Strings in BASH, an easier way?
Fred James
fredjame at fredjame.cnc.net
Fri Dec 26 11:43:01 CST 2008
Chris Cox wrote:
> Leroy Tennison wrote:
>
>> I'm wanting to split a string in BASH. I know about gawk and maybe sed
>> but I'm looking for a less involved solution. The simplest I've found
>> so far is the cut program but I'm wondering if there is something even
>> simpler.
>>
>> To add some context, what surfaced this is I wanted to do an apropos on
>> all programs in my path. What I have at this point is:
>>
>> for i in `echo $PATH | cut -d: -f1-30 --output-delimiter=" "`; do
>> for j in `ls -1 $i`; do apropos $j; read; done;
>> done
>>
>>
>
> My solution:
> echo "$PATH" | tr ':' ' ' | xargs ls -1 | xargs -n1 apropos -e
>
Chris Cox
"apropos: -e: unknown option"
However, it seems to work without the '-e' option, if this is what the
output is supposed to look like (see below)
Hope this helps
Regards
Fred James
$ echo "$PATH" | tr ':' ' ' | xargs ls -1 | xargs -n1 apropos | head -10
ls: cannot access /home/fredjame/bin: No such file or directory
/bin:: nothing appropriate
apropos (1) - search the whatis database for strings
ar (1) - create, modify, and extract from archives
ar (1p) - create and maintain library archives
arch (1) - print machine architecture
Archive::Cpio (3pm) - module for manipulations of cpio archives
Archive::Tar (3pm) - module for manipulations of tar archives
Archive::Tar::File (3pm) - a subclass for in-memory extracted file
from Archive::Tar
arch_prctl (2) - set architecture specific thread state
badblocks (8) - search a device for bad blocks
More information about the Discuss
mailing list