You certainly are very skilled at using bash, but don't you find that it
is slightly less flexible than if you were to simply write the whole
shebang in Perl? Your Perl comment below certainly suggests that you could
benefit from it.
use File::Basename;
my @cajones=fileparse('/secret/bigfoot-dna.fas');
and, when you decide to upgrade your servers to Windows, it will continue
to work...
On Thu, May 25, 2006 2:34 pm, Robert Citek wrote:
>
> That works. But I really do want the end result in a variable. I
> could redirect the output from the awk pipeline into a variable (e.g.
> file=$(...) ) but forking processes seems like overkill. But your
> suggestion which uses awk's auto-split feature did get me thinking about
> using an array in bash:
>
> echo foo.bar.txt | while IFS=. read -a file ; do echo ${file[1]}
> # the second field
> echo ${line[${#line}-2]} # the second to last field done
>
> Although I'm still wondering if there might be some other solutions.
> Ideally, I'm looking for something similar to perl's split or s///
> features but from within bash. I was thinking that 'set' might work, but
> didn't have any luck:
>
> This works:
> ( set foo bar txt ; echo $1 )
>
>
> This doesn't:
> ( IFS=. set foo.bar.txt ; echo $1 )
>
>
> Regards,
> - Robert
>
>
> On May 17, 2006, at 5:51 PM, Eric Wilson wrote:
>
>> How about this one:
>>
>>
>> [EMAIL PROTECTED]:~$ cat filename
>> foo.bar.txt joe.bar.junk www.big.bad.bar.goo
>>
>> ------ awk's NF var is Number of fields ---
>> ------ this would always spit out the second to the last field. ---
>>
>>
>>
>> [EMAIL PROTECTED]:~$ cat filename | \
>>
>>> while read FILE do echo $FILE | awk -F'.' '{print $(NF-1)}' done
>> bar bar bar
>>
>> Cheers;
>>
>>
>> E!
>>
>>
>>> Anyone have an alternate way to parse an environment variable?
>>>
>>>
>>> I have a filename in an environment variable that I'd like to parse.
>>> The filename is of the form "foo.bar.txt" and I'd like to parse out
>>> "bar". This is the solution I'm currently using:
>>>
>>>
>>> file=foo.bar.txt file=${file%.txt} file=${file#foo.}
>>>
>>> Any other solutions?
>>>
>
>
> _______________________________________________
> CWE-LUG mailing list
> [email protected]
> http://www.cwelug.org/
> http://www.cwelug.org/archives/
> http://www.cwelug.org/mailinglist/
>
>
_______________________________________________
CWE-LUG mailing list
[email protected]
http://www.cwelug.org/
http://www.cwelug.org/archives/
http://www.cwelug.org/mailinglist/