On Sun, 25 Mar 2001, Mike Noyes wrote:
> [EMAIL PROTECTED], 2001-03-25 15:14 -0800
> >On Sun, 25 Mar 2001, Mike Noyes wrote:
> >The g indicates multiple substitutions within the selected lines. My
> >mistake wsa in the line selection. I simplified things while testing
> >the command, and forgot to constrain it to the author table when I sent
> >that message.
> >
> >This version also handles quoting, I think.
> >
> >sed -e "/INSERT INTO
> >author/s/\((\('\([^'\]\|\\\.\)*',\)\{4\}\)'\([^']*\)',\([^)]*\)/\1'dummy',\
> >5/g"
>
> I'll try it later tonight. I'm new to regular expressions.
I've been using RE for a long time, just not sed-style. This has been
very interesting.
> Is this the way
> the regions are split? I didn't know you could nest them.
Yes indeed. The patterns are numbered by the left parenthesis.
>
> \((
> \(' # nested one level
> \([^'\]\|\\\.\) # nested two levels
> *',\) # nested one level
> \{4\}\)
> '\([^']*\)
> ',\([^)]*\)
>
> This will take me a couple of hours to decipher.
>
> >---------------------------------------------------------------------------
> >sed -e "/INSERT INTO author/s/\((\('\([^'\]\|\\\.\)*',\)\{4\}\)'\([^'\]\|\\
> >\.\)*',\([^)]*\)/\1'dummy',\5/g"
> >---------------------------------------------------------------------------
sed -e "/INSERT INTO author/s/
\( begin pattern 1
( opening parenthesis of record
\( begin pattern 2
' begin string literal
\( begin pattern 3
[^'\] anything but a single quote or backslash
\| or (this only works with gnu sed, apparently)
\\\. a backslash followed by any character
\)* end pattern 3 ... zero or more times
', end string literal
\)\{4\} end pattern 2 ... exactly four times
\) end pattern 1 ... exactly once, everything up to comma
before pwd
' begin pwd literal
\( begin pattern 4
[^'\] anything but a single quote or backslash
\| \\\. or a backslash followed by any character
\)* end pattern 4 ... zero or more times
', end pwd literal, and comma separator
\( begin pattern 5
[^)]* anything but a right paren ... zero or more times
\) end pattern 5
/ now begins substitution
\1 contents of pattern 1 (stuff beginning with left paren up
to comma before pwd literal
'dummy', new pwd literal
\5 contents of pattern 5 (stuff up to but not including
right paren
/g" end of substitution ... repeat throughout selected lines
> >
> >and the next one looks like it might work for users, but you should test
> >it out.
>
> I'll test it too. I'm getting a nice headache looking at these sed lines. ;)
Sleep and whitespace.
> >---------------------------------------------------------------------------
> >sed -e "/INSERT INTO user/s/(\(\('\([^'\]\|\\\.\)*',\)\{6\}\)'\([^'\]\|\\\.
> >\)*'\(,'\([^'\]\|\\\.\)*'\)\{11\}/\1'dummy',\5/g"
> >---------------------------------------------------------------------------
this one probably won't work, now that I look at it again... "user" has
non-string data fields. I also see that my substitution following pass is
not necessary, except perhaps as redundant insurance that a record with
the right number of fields is getting munged.
sed -e "/INSERT INTO user/s/
( opening parenthesis of record
\( begin pattern 1 (before pass)
\( begin pattern 2 (a field literal)
\( begin pattern 3 (a field literal followed by a comma)
' begin string literal
\( begin pattern 4
[^'\] anything but a single quote or backslash
\| \\\. or a backslash followed by any character
\)* end pattern 3 ... zero or more times
' end string literal
\| or
[0-9]* any digit ... zero or more times
\) end pattern 3 ... exactly once
, comma field delimiter
\)\{6\} end pattern 2 ... exactly six times
\) end pattern 1 ... exactly once, everything up to comma
before pass
' begin pass string literal
\( begin pattern 4
[^'\] anything but a single quote or backslash
\| \\\. or a backslash followed by any character
\)* end pattern 4 ... zero or more times
/
\1
'dummy
/g"
---------------------------------------------------------------------------
sed -e "/INSERT INTO user/s/(\(\(\('\([^'\]\|\\\.\)*'\|[0-9]*\),\)\{6\}\)'\
([^'\]\|\\\.\)*/\1'dummy/g"
---------------------------------------------------------------------------
> >
> > >
> > > author
> > > ('aid','name','url','email','pwd','counter')
> > >
> > > user
> > > ('uid','name','uname','email','femail','url','pass','storynum','\
> > > umode','uorder','thold','noscore','bio','ublockon','ublock','\
> > > theme','commentmax','counter')
> >
> >are you sure that the pwd field in the author table is password and not
> >present working directory? Users have a "pass" field... which would
> >appear to be inconsistent naming.
>
> I noticed that it was inconsistent too. The password field for author is
> pwd. I just double checked to make sure.
Okeydoke.
> Thanks for all the help. :-)
Thanks for all the work on Leaf. :)
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<[EMAIL PROTECTED]> Basics: ##.#. ##.#. Live Go...
Work:<[EMAIL PROTECTED]> Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...2k
---------------------------------------------------------------------------
_______________________________________________
Leaf-devel mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/leaf-devel