Re: how long does it take

From: Laurent Vogel (lvl_at_club-internet.fr)
Date: 07/29/03


Date: Tue, 29 Jul 2003 19:58:41 +0200


Arianne wrote:
> How long does it take [sed adepts] to write what looks
> like a complex sed script i.e. this one recently submitted here:
>
> sed '/[^ ]/{s/ *\(.\).*/\1/;H;d;};s/.*//;x;s/\n/ /g;s/ //' input > output
>
> I only use sed and other tools like it once every couple of months, and I
> always have to go back and look things up to remind myself of syntax and
> special character quoting etc.

Personnally I posess the syntax, and know what is easy to do and what
is not, so I can easily "visualize" what steps are easiest to take.
OTOH there are parts of SED which I don't master at all (intervals, for
instance), so I don't use these at all.

> I am just curious, when you're working with
> these tools everyday and you're smart and you have a good memory, can you
> think of how to do this and write it in like 20 secs, or do you have to
> scratch your head for a minute and make a quick trial version, or is
> it still more than 5 mins labour for you?

well, more like 5 minutes. I've got no problem of syntax. I first
paste a sample text in a file, then figure roughtly a logic in my head.
In this case, the logic is very simple:

  if there is a non-space char on the line | /[^ ]/{
  then keep it and remove everything else | s/ *\(.\).*/\1/
  accumulate it to the hold buffer | H
  and stop processing this line | d
                                              | }

now, I must print the line somehow, so there will be a kind of:
  get back the line from the hold buffer | g
  remove all \n | s/\n//g

and that's the first draft. All commands used there are very simple,
atomic commands (no complex regexps) so they are written very easily.

At this point I test, figure out that I've forgotten to clear the hold
buffer => replace 'g' by 's/.*//;x'
and also that an additional space should be deleted: 's/ //'

Of course if I really want to create a robust script, then I must
think of all which can go wrong (for instance here, the last line
is dropped if there is no empty line at the end), but for usenet
posts I think it suffices to illustrate how the real script can
work.

Laurent



Relevant Pages

  • Re: function definition syntax
    ... :> In which case it might as well be a separate script - you don't need a function. ... :>: That's much more reliable than having to remember which syntax ... Always using POSIX ... :> not overlook restoring IFS. ...
    (comp.unix.shell)
  • Re: Books/References new to scripting in AD/2003
    ... my own website has lots of script samples you might find useful: ... test bits of flag attributes like userAccountControl using SQL syntax. ... To restrict the query to an OU, ...
    (microsoft.public.windows.server.scripting)
  • Re: Books/References new to scripting in AD/2003
    ... Good luck with your scripting - It's a worthwhile pursuit and the time you spend learning to script can easily be re-paid. ... I don't believe there is any way to test bits of flag attributes like userAccountControl using SQL syntax. ... but needs to be enclosed in quotes in a query. ...
    (microsoft.public.windows.server.scripting)
  • Re: Legacy code/browser compatibility
    ... a user of such an ancient browsers may see a syntax error ... either script supported or not. ... browsers, script will be supported. ... that doesn't support object literals ...
    (comp.lang.javascript)
  • Re: Books/References new to scripting in AD/2003
    ... bits of flag attributes like userAccountControl using SQL syntax. ... To restrict the query to an OU, ... The equivalent LDAP syntax query would be: ... Here is the part of the script where it is pulling the info from AD. ...
    (microsoft.public.windows.server.scripting)