Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

different awk behaviour 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
0
0
PL

on AIX:
$ echo 123.123.123.123|awk -F. '$0~/^([0-9]{1,3}\.){3}[0-9]{1,3}$/'
123.123.123.123
$

on Redhat:
$ echo 123.123.123.123|awk -F. '$0~/^([0-9]{1,3}\.){3}[0-9]{1,3}$/'
$

why on redhad regex in awk does not work like on aix?
 
it works with --posix on redhat

$ echo 123.123.123.123|awk --posix -F. '$0~/^([0-9]{1,3}\.){3}[0-9]{1,3}$/'
123.123.123.123

I am just looking for something working in both AIX and Redhat (--posix switch is not option on AIX and command fails)
 
Hi

Is that Awk on RedHat a GNU Awk older than 4.0.0 ? Because those not processed regular expression intervals ( those quantifiers in braces ), unless [tt]--re-interval[/tt] switch was used. ( Or the [tt]--posix[/tt] you already discovered. )

If that is the case, as far as I know your only portable option is to not use intervals : [tt][0-9]{1,3}[/tt] -> [tt][0-9][0-9]?[0-9]?[/tt]

Feherke.
feherke.ga
 
thank you. brilliant!

$ echo 23.3.23.1|awk -F. '$0~/^[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$/'
23.3.23.1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top