Unix Programming - awk gsub command

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2007 > awk gsub command





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author awk gsub command
james.mork@gmail.com

2007-02-23, 1:18 pm

Hi,
I am new to awk scripting and trying to figure how to use gsub
command.

In this example:

gsub(/^[ \t]+|[ \t]+$/,"",mgev_tx)

what is /^[ \t]+|[ \t]+$/ doing?

Jens Thoms Toerring

2007-02-23, 1:18 pm

james.mork@gmail.com wrote:
> I am new to awk scripting and trying to figure how to use gsub
> command.


> In this example:


> gsub(/^[ \t]+|[ \t]+$/,"",mgev_tx)


> what is /^[ \t]+|[ \t]+$/ doing?


The '^[ \t]+' bit means at least one (or more) spaces or tab
characters at the beginning of the string and the '[ \t]+$'
means at least one (or more) spaces or tab characters at the
end of the string. The '|' means 'or', so this matches all
spaces/tabs at the very start or the very end of a string.
Looks like the wole thing is meant to remove all white space
the start and end of a string stored in 'mgev_txt'.

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com