[NTLUG:Discuss] Strings in BASH, an easier way?

Leroy Tennison leroy_tennison at prodigy.net
Sun Dec 28 02:57:03 CST 2008


Chris Cox wrote:
> Fred James wrote:
>> 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"
> 
> Well... if you have an apropos with the "-r" option you can
> simulate an "exact" pattern match (what -e does on distros with
> that option).  Alternatively you can look into doing
> a man -f instead (but if you don't have apropos -e, you probably
> don't have man -f either).
> 
> The problem is that apropos is a keyword search... and specifically
> I think you want the man page description text associated with the
> exact command.  Naturally, none of this is perfect... but if
> you can use apropos -e or man -f, it gets pretty close.
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
> 

 > Naturally, none of this is perfect...

Am I ever discovering that.   Many programs have nothing, some find too 
much (like X11).  However, overall it's an interesting exercise to see 
what additional useful programs you can discover, I've probably found 
10+ so far.



More information about the Discuss mailing list