www.ShoppingPodder.com

Leading Computer Shopping,
News and information


Part of the Identityscape.com network...

getxfactor.com jmoodmusic.com smartbusinesschoices.com mintdepot.com lowfaresalways.com evangelicalview.com shoppingpodder.com soproudlywehail.com webnews.ws currenthumor.com

 

 

[OT] Utility to convert ex editor commands to awk scripts?
   Shopping Podder - the Best of Computer Postings! Forum Index -> Computer - Editors  
View previous topic :: View next topic  
Author Message
Rod Pemberton
Guest






PostPosted: Sun Oct 19, 2008 2:06 pm    Post subject: [OT] Utility to convert ex editor commands to awk scripts? Reply with quote

Is there a utility to parse a few/many/all of the ex line editor's text
editing commands (or vi's ex mode commands) and generate the equivalent awk
script? ex2awk?

In particular, the subset of global edit commands: g, v, s; the display
command: p; the editing command: d; and combinations of, e.g, g or v with s,
would be sufficient. For RE's, ^ start-of-line, end-of-line $, . single
char, * multiple char, [] character set, \{n\} count, and ASCII char's would
be sufficient.


Rod Pemberton
Back to top
Rod Pemberton
Guest






PostPosted: Sun Oct 19, 2008 4:13 pm    Post subject: Re: [OT] Utility to convert ex editor commands to awk script Reply with quote

"Janis Papanagnou" <janis_papanagnou@hotmail.com> wrote in message
news:gdf0hb$34j$1@svr7.m-online.net...
Quote:
Rod Pemberton wrote:
Is there a utility to parse a few/many/all of the ex line editor's text
editing commands (or vi's ex mode commands) and generate the equivalent
awk
script? ex2awk?

Never heard of existing converters.

In particular, the subset of global edit commands: g, v, s; the display
command: p; the editing command: d; and combinations of, e.g, g or v
with s,
would be sufficient. For RE's, ^ start-of-line, end-of-line $, . single
char, * multiple char, [] character set, \{n\} count, and ASCII char's
would
be sufficient.

Some of the simpler processings... (untested, so be careful with that
code)

ex/vi awk

s/pat-1/repl/ {sub(/pat-1/,"repl")}{print}

s/pat-1/repl/g {gsub(/pat-1/,"repl")}{print}


Some non-trivial ones...

g/pat-1/s/pat-2/repl/ /pat-1/{gsub(/pat-2/,"repl")}{print}

v/pat-1/s/pat-2/repl/ !/pat-1/{gsub(/pat-2/,"repl")}{print}


Wouldn't those be 'sub'? I.e., isn't there a difference between these two?

g/pat-1/s/pat-2/repl/

g/pat-1/s/pat-2/repl/g


Quote:
g/pat-1/d /pat-1/{next}{print}

v/pat-1/d !/pat-1/{next}{print}


But note that ex expressions can get even more complex, e.g.

5,8g/pat-1/s/pat-2/repl/ NR>=5 && NR<=8 && /pat-1/{
gsub(/pat-2/,"repl")}{print}

Or something that I currently won't even try to transform - though
possible to do in principle

/pat-1//pat-2/s/pat-3/repl/


Maybe you can use the examples for something, or write a simple
converter yourself; a lot of what you want may be covered by the
examples and a generator seems to be straightforward to develop.


Thank you! Very informative. I appreciate that you worked out the
combinations - even if "untested". As long as the anchors (^,$) are the
same for AWK RE's, those will probably do. So, I might not need the
utility... But, I still think it might be interesting: ex2awk, awk2c,
dedicated executable that does customized editing and/or parsing... vi's
ubiquitousness means many people are familiar with ex commands, who might
not be familiar with awk.


RP
PS. I almost missed your reply though. You dropped the other ng's... I
was Googling NG's for related info and saw it. I was watching alt.lang.awk
but not through Google Groups. I added them back in case someone else was
reading the thread on them. I hope you don't mind.
Back to top
Rugxulo
Guest






PostPosted: Sat Oct 25, 2008 7:13 pm    Post subject: Re: Utility to convert ex editor commands to awk scripts? Reply with quote

On Oct 19, 4:06 am, "Rod Pemberton" <do_not_h...@nohavenot.cmm> wrote:
Quote:
Is there a utility to parse a few/many/all of the ex line editor's text
editing commands (or vi's ex mode commands) and generate the equivalent awk
script?  ex2awk?

In particular, the subset of global edit commands: g, v, s; the display
command: p; the editing command: d; and combinations of, e.g, g or v with s,
would be sufficient.  For RE's, ^ start-of-line, end-of-line $, . single
char, * multiple char, [] character set, \{n\} count, and ASCII char's would
be sufficient.

There's some good stuff (including an awk <-> sed chart) on Eric
Pement's site (although it may not be exactly what you wanted):

http://www.pement.org/awk.htm
Back to top
Display posts from previous:   
   Shopping Podder - the Best of Computer Postings! Forum Index -> Computer - Editors  
Page 1 of 1
All times are GMT

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum