[Novalug] Please help with RegEx in GNU Gawk

James Ewing Cottrell 3rd JECottrell3 at Comcast.NET
Mon Oct 10 21:02:40 EDT 2011


  AWK exists in that middle ground between SH and Perl.

And...it's awkward. Perl provides better RE's and even has an AWK mode.

JIM

On 10/10/2011 8:47 PM, Ed James wrote:
> Why not?  Just tried it, works fine for me:
>
> [root at nick TEST]# awk -f trim-test.awk
>> hello<
>> hello<
> [root at nick TEST]#
>
> No changes to code made by me at all.
>
> Ed James
>
> On Mon, Oct 10, 2011 at 8:35 PM, James Ewing Cottrell 3rd
> <JECottrell3 at comcast.net>  wrote:
>>   [1] Never Use AWK. Use Perl, Python, or Ruby.
>> [2] Never use those stupid [[:whatever:]] constructs.
>>
>> JIM
>>
>> On 9/25/2011 5:35 PM, Jim Ide wrote:
>>> Goal: write a TRIM function that deletes leading whitespace
>>> characters from the left end of a string.  See program below.
>>>
>>> When I run this, I get:
>>>
>>> $ awk -f trim-test.awk
>>>> hello<
>>>>      hello<
>>> $
>>>
>>> Why does [[:space:]] not work in trim_v2 as expected?
>>>
>>> Thanks for your help.
>>>
>>>
>>>
>>> BEGIN {
>>>        temp = "    hello"
>>>        print ">" ltrim_v1(temp)"<"
>>>        print ">" ltrim_v2(temp)"<"
>>>        exit
>>> }
>>>
>>> function ltrim_v1(str) {
>>>        # Delete leading whitespace (spaces and tabs) from the beginning of each line
>>>        sub(/^[ \t]+/, "", str)
>>>        return str
>>> }
>>>
>>> function ltrim_v2(str) {
>>>        # Delete leading whitespace (spaces and tabs) from the beginning of each line
>>>        sub(/^[[:space:]]+/, "", str)
>>>        return str
>>> }
>>>
>>> _______________________________________________
>>> Novalug mailing list
>>> Novalug at calypso.tux.org
>>> http://calypso.tux.org/mailman/listinfo/novalug
>>>
>> _______________________________________________
>> Novalug mailing list
>> Novalug at calypso.tux.org
>> http://calypso.tux.org/mailman/listinfo/novalug
>>
> _______________________________________________
> Novalug mailing list
> Novalug at calypso.tux.org
> http://calypso.tux.org/mailman/listinfo/novalug
>




More information about the Novalug mailing list