Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: awk challenge
Either put up or shut up. (I believe this is a very usefulness of this
function is self-evident - specification of table can be defined at
beginning by only specifying the delimiter strings.)

Here's my version,  "matchCol(s, r, bA)", where s is the source line, r is
regexp spefying delimiter b/w columns; bA[1..] is resultant array of
columns.

--------------

function matchCol(s, r, bA) {
bL=0
if (match(s, r)) {if (RSTART!=1) bA[++bL]= 1}
else bA[++bL]= 1
bL= matchCol2(s, r, bA, 0, bL)
if (bA[bL-1]>bA[bL]) bL-= 2 # if end is regexp
return bL
}

function matchCol2(s, r, bA, posn, bL) {
print "incoming s=" s", bL="bL", bA[bL]="bA[bL]
if (match(s, r)) {
if (bL) bA[++bL]= posn+RSTART-1       # before current regexp
if (bA[bL]+1==bA[bL-1]) bL-= 2    # if regexp is same as last
bA[++bL]= posn+RSTART+RLENGTH         # after current regexp
bL= matchCol2(substr(s, RSTART+RLENGTH), r, bA, bA[bL]-1, bL)
}
else bA[++bL]= posn+length(s)      # before last regexp
return bL
}



Report this thread to moderator Post Follow-up to this message
Old Post
A Ferenstein
11-16-04 11:50 PM


Re: awk challenge
The posted code fails when s = "   " and r = " +".

Try this:

function match_cols( s, regexp, a,       i,first,offset,len )
{ first = 1
while ( match( s, regexp) )
{ if ( RSTART > 1 )
{ RSTART += offset
a[++i] = first
a[++i] = RSTART - 1
}
sub( regexp, "", s )
offset += RLENGTH
first = RSTART + RLENGTH
}
len = length(s) + offset
if ( len >= first )
{ a[++i] = first
a[++i] = len
}
return i
}

Report this thread to moderator Post Follow-up to this message
Old Post
William James
11-19-04 08:55 AM


Re: awk challenge
In article <f8860640.0411181709.7e50215b@posting.google.com>,
William James <w_a_x_man@yahoo.com> wrote:
>The posted code fails when s = "   " and r = " +".
>

What's this supposed to do?

>
>function match_cols( s, regexp, a,       i,first,offset,len )
>{ first = 1
>  while ( match( s, regexp) )
>  { if ( RSTART > 1 )
>    { RSTART += offset
>      a[++i] = first
>      a[++i] = RSTART - 1
>    }
>    sub( regexp, "", s )
>    offset += RLENGTH
>    first = RSTART + RLENGTH
>  }
>  len = length(s) + offset
>  if ( len >= first )
>  { a[++i] = first
>    a[++i] = len
>  }
>  return i
>}



Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
11-19-04 08:55 AM


Re: awk challenge
In article <f8860640.0411181709.7e50215b@posting.google.com>,
William James <w_a_x_man@yahoo.com> wrote:
>The posted code fails when s = "   " and r = " +".
>

What's this supposed to do?

>
>function match_cols( s, regexp, a,       i,first,offset,len )
>{ first = 1
>  while ( match( s, regexp) )
>  { if ( RSTART > 1 )
>    { RSTART += offset
>      a[++i] = first
>      a[++i] = RSTART - 1
>    }
>    sub( regexp, "", s )
>    offset += RLENGTH
>    first = RSTART + RLENGTH
>  }
>  len = length(s) + offset
>  if ( len >= first )
>  { a[++i] = first
>    a[++i] = len
>  }
>  return i
>}



Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
11-23-04 01:55 AM


Re: awk challenge
The posted code fails when s = "   " and r = " +".

Try this:

function match_cols( s, regexp, a,       i,first,offset,len )
{ first = 1
while ( match( s, regexp) )
{ if ( RSTART > 1 )
{ RSTART += offset
a[++i] = first
a[++i] = RSTART - 1
}
sub( regexp, "", s )
offset += RLENGTH
first = RSTART + RLENGTH
}
len = length(s) + offset
if ( len >= first )
{ a[++i] = first
a[++i] = len
}
return i
}

Report this thread to moderator Post Follow-up to this message
Old Post
William James
11-23-04 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:07 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.