[Novalug] Please help with RegEx in GNU Gawk
James Ewing Cottrell 3rd
JECottrell3 at Comcast.NET
Mon Oct 10 20:35:54 EDT 2011
[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
>
More information about the Novalug
mailing list