Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[OT] Utility to convert ex editor commands to awk scripts?

12 views
Skip to first unread message

Rod Pemberton

unread,
Oct 19, 2008, 5:06:33 AM10/19/08
to
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

Rod Pemberton

unread,
Oct 19, 2008, 7:13:46 AM10/19/08
to
"Janis Papanagnou" <janis_pa...@hotmail.com> wrote in message
news:gdf0hb$34j$1...@svr7.m-online.net...

> 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


> 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.

Rugxulo

unread,
Oct 25, 2008, 3:13:03 PM10/25/08
to

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

0 new messages