[Novalug] Please help with RegEx in GNU Gawk

Ed James edward.james@gmail.com
Mon Oct 10 20:47:42 EDT 2011


Why not?  Just tried it, works fine for me:

[root@nick TEST]# awk -f trim-test.awk
>hello<
>hello<
[root@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@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@calypso.tux.org
>> http://calypso.tux.org/mailman/listinfo/novalug
>>
>
> _______________________________________________
> Novalug mailing list
> Novalug@calypso.tux.org
> http://calypso.tux.org/mailman/listinfo/novalug
>



More information about the Novalug mailing list