traslate grep expresion to detect COMMENT in line sql

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

traslate grep expresion to detect COMMENT in line sql

PICCORO McKAY Lenz
i have a sql file that hava also lines like :

COMMENT " xxxx " , field f2 \n

in console with this grep/sed can sustituye multilines or single lines

sed -ne '/comment/{:;/\o47;\s*$/!{N;b};s/\n\s*/ /;p}' <file

but i need tho detect at the end of the COMMENT the ", secuence to
sustitute to "*/"

my target objetive it parse a text/line like this:

 fiel1 TEXT COMMENT "coment fiel1" , field2 TEXT, fiel3 TEXT
 fiel4 NUMBER(10,2), fiel5 TEXT COMMENT "pepepeep",
 fiel6 TEXT

into this:

 fiel1 TEXT /* coment fiel1*/ , field2 TEXT, fiel3 TEXT
 fiel4 NUMBER(10,2), fiel5 TEXT /*pepepeep*/,
 fiel6 TEXT

please help, its fine with REPLACE() but not always the secuence ' ", '
will be in same order/sapces combination, maybe could be ' "     , ' or
with new line

Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: traslate grep expresion to detect COMMENT in line sql

Fernando Cabral
2017-07-28 11:57 GMT-03:00 PICCORO McKAY Lenz <[hidden email]>:

>
> my target objetive it parse a text/line like this:
>
>  fiel1 TEXT COMMENT "coment fiel1" , field2 TEXT, fiel3 TEXT
>  fiel4 NUMBER(10,2), fiel5 TEXT COMMENT "pepepeep",
>  fiel6 TEXT
>
> into this:
>
>  fiel1 TEXT /* coment fiel1*/ , field2 TEXT, fiel3 TEXT
>  fiel4 NUMBER(10,2), fiel5 TEXT /*pepepeep*/,
>  fiel6 TEXT
>

Let me see if I have understood this well enough:
a) find the word " COMMENT " (whitespace before and after), followed by
whatever till you find a "," (comma)
b) Delede " COMMENT " and put "whatever" between "/*" and "*/"
c) Leave untouched whatever is after the first "," (comma) including the
comma itself.

Is that right? If it is, you should start by compiling this regular
expression:

"^(.*?) COMMENT +?(".*?")(,.*?)"

And the replace by: "&1 \*&2*/&3"  (scape as needed) and this should work.

what it does:
a) from the start of the line, find whatever exists until the expression "
COMMENT " -- which should not be included.
b) Save that firt part into the buffer number 1
c) Skip til after the last white space after " COMMENT " - throw that away
d) save the next portion between double quotes and save into buffer number 2
e) Save next portion into buffer number 3

Put back the contents from buffer 1, add "\*", put back the contents of
buffer 2, add "*/" and then put back the contents of buffer number 3.

You may have to tinker around a little, but I think this contains the basic
ideia.

- fernando




Lenz McKAY Gerardo (PICCORO)

> http://qgqlochekone.blogspot.com
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: [hidden email]
Facebook: [hidden email]
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: traslate grep expresion to detect COMMENT in line sql

PICCORO McKAY Lenz
wow! i must made a string search procedure until "comment" was find.. !

i think that but i also think that a reg expresion must be better with pcre
component!

Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com

2017-07-28 11:34 GMT-04:00 Fernando Cabral <[hidden email]>:

> 2017-07-28 11:57 GMT-03:00 PICCORO McKAY Lenz <[hidden email]>:
>
> >
> > my target objetive it parse a text/line like this:
> >
> >  fiel1 TEXT COMMENT "coment fiel1" , field2 TEXT, fiel3 TEXT
> >  fiel4 NUMBER(10,2), fiel5 TEXT COMMENT "pepepeep",
> >  fiel6 TEXT
> >
> > into this:
> >
> >  fiel1 TEXT /* coment fiel1*/ , field2 TEXT, fiel3 TEXT
> >  fiel4 NUMBER(10,2), fiel5 TEXT /*pepepeep*/,
> >  fiel6 TEXT
> >
>
> Let me see if I have understood this well enough:
> a) find the word " COMMENT " (whitespace before and after), followed by
> whatever till you find a "," (comma)
> b) Delede " COMMENT " and put "whatever" between "/*" and "*/"
> c) Leave untouched whatever is after the first "," (comma) including the
> comma itself.
>
> Is that right? If it is, you should start by compiling this regular
> expression:
>
> "^(.*?) COMMENT +?(".*?")(,.*?)"
>
> And the replace by: "&1 \*&2*/&3"  (scape as needed) and this should work.
>
> what it does:
> a) from the start of the line, find whatever exists until the expression "
> COMMENT " -- which should not be included.
> b) Save that firt part into the buffer number 1
> c) Skip til after the last white space after " COMMENT " - throw that away
> d) save the next portion between double quotes and save into buffer number
> 2
> e) Save next portion into buffer number 3
>
> Put back the contents from buffer 1, add "\*", put back the contents of
> buffer 2, add "*/" and then put back the contents of buffer number 3.
>
> You may have to tinker around a little, but I think this contains the basic
> ideia.
>
> - fernando
>
>
>
>
> Lenz McKAY Gerardo (PICCORO)
>
> > http://qgqlochekone.blogspot.com
> > ------------------------------------------------------------
> > ------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > _______________________________________________
> > Gambas-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
>
>
>
> --
> Fernando Cabral
> Blogue: http://fernandocabral.org
> Twitter: http://twitter.com/fjcabral
> e-mail: [hidden email]
> Facebook: [hidden email]
> Telegram: +55 (37) 99988-8868
> Wickr ID: fernandocabral
> WhatsApp: +55 (37) 99988-8868
> Skype:  fernandojosecabral
> Telefone fixo: +55 (37) 3521-2183
> Telefone celular: +55 (37) 99988-8868
>
> Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
> nenhum político ou cientista poderá se gabar de nada.
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: traslate grep expresion to detect COMMENT in line sql

Fernando Cabral
2017-07-28 12:50 GMT-03:00 PICCORO McKAY Lenz <[hidden email]>:

> wow! i must made a string search procedure until "comment" was find.. !
>
> i think that but i also think that a reg expresion must be better with pcre
> component!
>

My suggestion it to be used with pcre componte. I only gave you the search
and replace regular expression. Something like

NewLine  = RegExp.Replace(OldLIne,
"^(.*?) COMMENT +?(".*?")(,.*?)", "&1 \*&2*/&3", RegExp.UTF8)

But, since I presume you'll be using it several times, then it will be more
efficiente if you compile it first.

- fernando

Lenz McKAY Gerardo (PICCORO)

> http://qgqlochekone.blogspot.com
>
> 2017-07-28 11:34 GMT-04:00 Fernando Cabral <[hidden email]>:
>
> > 2017-07-28 11:57 GMT-03:00 PICCORO McKAY Lenz <[hidden email]>:
> >
> > >
> > > my target objetive it parse a text/line like this:
> > >
> > >  fiel1 TEXT COMMENT "coment fiel1" , field2 TEXT, fiel3 TEXT
> > >  fiel4 NUMBER(10,2), fiel5 TEXT COMMENT "pepepeep",
> > >  fiel6 TEXT
> > >
> > > into this:
> > >
> > >  fiel1 TEXT /* coment fiel1*/ , field2 TEXT, fiel3 TEXT
> > >  fiel4 NUMBER(10,2), fiel5 TEXT /*pepepeep*/,
> > >  fiel6 TEXT
> > >
> >
> > Let me see if I have understood this well enough:
> > a) find the word " COMMENT " (whitespace before and after), followed by
> > whatever till you find a "," (comma)
> > b) Delede " COMMENT " and put "whatever" between "/*" and "*/"
> > c) Leave untouched whatever is after the first "," (comma) including the
> > comma itself.
> >
> > Is that right? If it is, you should start by compiling this regular
> > expression:
> >
> > "^(.*?) COMMENT +?(".*?")(,.*?)"
> >
> > And the replace by: "&1 \*&2*/&3"  (scape as needed) and this should
> work.
> >
> > what it does:
> > a) from the start of the line, find whatever exists until the expression
> "
> > COMMENT " -- which should not be included.
> > b) Save that firt part into the buffer number 1
> > c) Skip til after the last white space after " COMMENT " - throw that
> away
> > d) save the next portion between double quotes and save into buffer
> number
> > 2
> > e) Save next portion into buffer number 3
> >
> > Put back the contents from buffer 1, add "\*", put back the contents of
> > buffer 2, add "*/" and then put back the contents of buffer number 3.
> >
> > You may have to tinker around a little, but I think this contains the
> basic
> > ideia.
> >
> > - fernando
> >
> >
> >
> >
> > Lenz McKAY Gerardo (PICCORO)
> >
> > > http://qgqlochekone.blogspot.com
> > > ------------------------------------------------------------
> > > ------------------
> > > Check out the vibrant tech community on one of the world's most
> > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > > _______________________________________________
> > > Gambas-user mailing list
> > > [hidden email]
> > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >
> >
> >
> >
> > --
> > Fernando Cabral
> > Blogue: http://fernandocabral.org
> > Twitter: http://twitter.com/fjcabral
> > e-mail: [hidden email]
> > Facebook: [hidden email]
> > Telegram: +55 (37) 99988-8868
> > Wickr ID: fernandocabral
> > WhatsApp: +55 (37) 99988-8868
> > Skype:  fernandojosecabral
> > Telefone fixo: +55 (37) 3521-2183
> > Telefone celular: +55 (37) 99988-8868
> >
> > Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
> > nenhum político ou cientista poderá se gabar de nada.
> > ------------------------------------------------------------
> > ------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > _______________________________________________
> > Gambas-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: [hidden email]
Facebook: [hidden email]
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: traslate grep expresion to detect COMMENT in line sql

PICCORO McKAY Lenz
umm RegExp.Replace are only since 3.5 .. searching for alternatives, due i
have for now Debian wheeze and the gamgas (with supoport by vendor) are 3.1

any ideas?

Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com

2017-07-28 13:51 GMT-04:00 Fernando Cabral <[hidden email]>:

> 2017-07-28 12:50 GMT-03:00 PICCORO McKAY Lenz <[hidden email]>:
>
> > wow! i must made a string search procedure until "comment" was find.. !
> >
> > i think that but i also think that a reg expresion must be better with
> pcre
> > component!
> >
>
> My suggestion it to be used with pcre componte. I only gave you the search
> and replace regular expression. Something like
>
> NewLine  = RegExp.Replace(OldLIne,
> "^(.*?) COMMENT +?(".*?")(,.*?)", "&1 \*&2*/&3", RegExp.UTF8)
>
> But, since I presume you'll be using it several times, then it will be more
> efficiente if you compile it first.
>
> - fernando
>
> Lenz McKAY Gerardo (PICCORO)
> > http://qgqlochekone.blogspot.com
> >
> > 2017-07-28 11:34 GMT-04:00 Fernando Cabral <[hidden email]
> >:
> >
> > > 2017-07-28 11:57 GMT-03:00 PICCORO McKAY Lenz <[hidden email]
> >:
> > >
> > > >
> > > > my target objetive it parse a text/line like this:
> > > >
> > > >  fiel1 TEXT COMMENT "coment fiel1" , field2 TEXT, fiel3 TEXT
> > > >  fiel4 NUMBER(10,2), fiel5 TEXT COMMENT "pepepeep",
> > > >  fiel6 TEXT
> > > >
> > > > into this:
> > > >
> > > >  fiel1 TEXT /* coment fiel1*/ , field2 TEXT, fiel3 TEXT
> > > >  fiel4 NUMBER(10,2), fiel5 TEXT /*pepepeep*/,
> > > >  fiel6 TEXT
> > > >
> > >
> > > Let me see if I have understood this well enough:
> > > a) find the word " COMMENT " (whitespace before and after), followed by
> > > whatever till you find a "," (comma)
> > > b) Delede " COMMENT " and put "whatever" between "/*" and "*/"
> > > c) Leave untouched whatever is after the first "," (comma) including
> the
> > > comma itself.
> > >
> > > Is that right? If it is, you should start by compiling this regular
> > > expression:
> > >
> > > "^(.*?) COMMENT +?(".*?")(,.*?)"
> > >
> > > And the replace by: "&1 \*&2*/&3"  (scape as needed) and this should
> > work.
> > >
> > > what it does:
> > > a) from the start of the line, find whatever exists until the
> expression
> > "
> > > COMMENT " -- which should not be included.
> > > b) Save that firt part into the buffer number 1
> > > c) Skip til after the last white space after " COMMENT " - throw that
> > away
> > > d) save the next portion between double quotes and save into buffer
> > number
> > > 2
> > > e) Save next portion into buffer number 3
> > >
> > > Put back the contents from buffer 1, add "\*", put back the contents of
> > > buffer 2, add "*/" and then put back the contents of buffer number 3.
> > >
> > > You may have to tinker around a little, but I think this contains the
> > basic
> > > ideia.
> > >
> > > - fernando
> > >
> > >
> > >
> > >
> > > Lenz McKAY Gerardo (PICCORO)
> > >
> > > > http://qgqlochekone.blogspot.com
> > > > ------------------------------------------------------------
> > > > ------------------
> > > > Check out the vibrant tech community on one of the world's most
> > > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > > > _______________________________________________
> > > > Gambas-user mailing list
> > > > [hidden email]
> > > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > > >
> > >
> > >
> > >
> > > --
> > > Fernando Cabral
> > > Blogue: http://fernandocabral.org
> > > Twitter: http://twitter.com/fjcabral
> > > e-mail: [hidden email]
> > > Facebook: [hidden email]
> > > Telegram: +55 (37) 99988-8868
> > > Wickr ID: fernandocabral
> > > WhatsApp: +55 (37) 99988-8868
> > > Skype:  fernandojosecabral
> > > Telefone fixo: +55 (37) 3521-2183
> > > Telefone celular: +55 (37) 99988-8868
> > >
> > > Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
> > > nenhum político ou cientista poderá se gabar de nada.
> > > ------------------------------------------------------------
> > > ------------------
> > > Check out the vibrant tech community on one of the world's most
> > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > > _______________________________________________
> > > Gambas-user mailing list
> > > [hidden email]
> > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >
> > ------------------------------------------------------------
> > ------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > _______________________________________________
> > Gambas-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
>
>
>
> --
> Fernando Cabral
> Blogue: http://fernandocabral.org
> Twitter: http://twitter.com/fjcabral
> e-mail: [hidden email]
> Facebook: [hidden email]
> Telegram: +55 (37) 99988-8868
> Wickr ID: fernandocabral
> WhatsApp: +55 (37) 99988-8868
> Skype:  fernandojosecabral
> Telefone fixo: +55 (37) 3521-2183
> Telefone celular: +55 (37) 99988-8868
>
> Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
> nenhum político ou cientista poderá se gabar de nada.
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Loading...