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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help about delimiters

Status
Not open for further replies.

talun

Technical User
Feb 22, 2006
2
IT
Good morning to all.
I'm a AWK beginner and I would like to know if it is possible to define the FS variable in a such way that I'm able to read fields delimited by different delimiters.
For example I need to extract the numeric values from a record set where the values are delimited by spaces, brackets and commas (see below)

Trace Length [m] 1.34E+00 +- 4.85E-01 (5.38E-01, 2.29E+00)

I'm using gawk with Windows XP.

Can anyone help me?

Thanks!

Sergio
 
Hi

[tt]gawk[/tt] ( and as far as I heard [tt]mawk[/tt] too ) accept regular expressions as field delimiter. Theoretically this should work :
Code:
[blue]c:\>[/blue] type script.awk
BEGIN {
  FS="[ (),]"
}
{
  for (i=0;i<=NF;i++) print i,$i
}
[blue]c:\>[/blue] echo "Trace Length [m]  1.34E+00 +- 4.85E-01  (5.38E-01, 2.29E+00)" | awk -f script.awk
0 Trace Length [m]  1.34E+00 +- 4.85E-01  (5.38E-01, 2.29E+00)
1 Trace
2 Length
3 [m]
4 
5 1.34E+00
6 +-
7 4.85E-01
8 
9 
10 5.38E-01
11 
12 2.29E+00
13

Feherke.
 
Hi feherke, many thanks for your reply.

bye
Sergio
 
All modern awks accept regular expressions as field delimiter. Mawk and gawk are alone in accepting regexps as record-separators. Not even Perl or Ruby will do that. (Probably because regexps are more powerful in those languages.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top