Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, Is it possible to change each line of a file as shown in the examples below: hello becomes [Hh]-[Ee]-[Ll]-[Ll]-[Oo] there becomes [Tt]-[Hh]-[Ee]-[Rr]-[Ee] and so on? Many Thanks, Jonny
Post Follow-up to this messageThis crashes on my computer. Could it be a Unix-only solution?
Do it this way:
BEGIN { FS=""; OFS="]-[" }
{ for (i=1; i<=NF; i++)
$i=toupper($i)tolower($i)
print "[" $0 "]" }
Post Follow-up to this messageWilliam James wrote: > This crashes on my computer. Could it be a Unix-only solution? Hmm.. Not as far as I see. Did you see anything in Ed's solution that is non-standard awk? Or OS dependent? Indications are welcome. (Or maybe it's a problem of the specific awk/OS set you are using?) Janis
Post Follow-up to this messageOn Thu, 30 Dec 2004 01:45:51 +0100, Janis Papanagnou <Janis_Papanagnou@hotmail.com> wrote: >William James wrote: > >Hmm.. Not as far as I see. Did you see anything in Ed's solution >that is non-standard awk? Or OS dependent? Indications are welcome. >(Or maybe it's a problem of the specific awk/OS set you are using?) It's completely Unix ... or at least non-Microsoft. Line continuation is available in some Windows versions, but it doesn't work the same way. Inline programs have to be enclosed in "" instead of '', and internal "s escaped with a backslash (even then, there can be problems with quotes that were already escaped: too many backslashes tends to break things). The printf and for syntaxes are broken: () must be used without a space following the function name. etc., etc., etc. This varies somewhat with the specific awk port and version. Most Unix gawk scrips work in Cygwin under Windws. -- T.E.D. (tdavis@gearbox.maem.umr.edu)
Post Follow-up to this messageTed Davis wrote: > On Thu, 30 Dec 2004 01:45:51 +0100, Janis Papanagnou > <Janis_Papanagnou@hotmail.com> wrote: > > > > > It's completely Unix ... or at least non-Microsoft. Line continuation > is available in some Windows versions, but it doesn't work the same > way. Inline programs have to be enclosed in "" instead of '', and > internal "s escaped with a backslash Then that can't be the problem William's encountered since he doesn't escape his backslashes. William - which awk/OS are you using and what part of the script is causing the problem? (even then, there can be problems > with quotes that were already escaped: too many backslashes tends to > break things). The printf and for syntaxes are broken: () must be > used without a space following the function name. etc., etc., etc. > This varies somewhat with the specific awk port and version. Most > Unix gawk scrips work in Cygwin under Windws. > Thanks for the information. I don't think you're suggesting we start writing our scripts to accomodate those MS peculiarities, but it's good to know they exist. Ed.
Post Follow-up to this messageIn article <geOdnTUJLaBdn0ncRVn-qg@comcast.com>,
Ed Morton <morton@lsupcaemnt.com> wrote:
...
>Thanks for the information. I don't think you're suggesting we start
>writing our scripts to accomodate those MS peculiarities, but it's good
>to know they exist.
In the category of "water is wet", we shouldn't be writing
shell/COMMAND.COM/CMD.EXE scripts at all in this ng. We should, of course,
be writing AWK. It is up to the user to make it work on his/her
implementaiton.
OBonTopic: BEGIN {print "hello, world"}
Post Follow-up to this messageTed Davis wrote: > On Thu, 30 Dec 2004 01:45:51 +0100, Janis Papanagnou > <Janis_Papanagnou@hotmail.com> wrote: > > It's completely Unix ... or at least non-Microsoft. I won't say that awk syntax has primarily to do (ignoring path and other interface issues, which are not present in Ed's solution anyway - where the only deviation seems to be the inline call syntax) with Unix or MS. But if you want to put it that way; the latter, I'd say, since the awk syntax seems completely valid to me. > Line continuation is available in some Windows versions, but it doesn't > work the same way. Would standard awk programs work on WinDos if put in a file and started by "awk -f ..."? > Inline programs have to be enclosed in "" instead of '', and internal "s That's a WinDos shells issue, then, isn't it? William has just omitted the surrounding call syntax in his solution. I think that people in c.l.a are capable of identifying the awk program within a non-MS like awk -f '...' call. > escaped with a backslash (even then, there can be problems with quotes tha t > were already escaped: too many backslashes tends to break things). The > printf and for syntaxes are broken: () must be used without a space > following the function name. So WinDos' awk's do not conform to the standard? Too bad. > etc., etc., etc. This varies somewhat with the specific awk port and > version. Most Unix gawk scrips work in Cygwin under Windws. Would you say we should on WinDos, if possible, use awk under Cygwin, only, to avoid bad surprises? Janis
Post Follow-up to this message
Kenny McCormack wrote:
> In article <geOdnTUJLaBdn0ncRVn-qg@comcast.com>,
> Ed Morton <morton@lsupcaemnt.com> wrote:
> ...
>
>
>
> In the category of "water is wet", we shouldn't be writing
> shell/COMMAND.COM/CMD.EXE scripts at all in this ng. We should, of course
,
> be writing AWK. It is up to the user to make it work on his/her
> implementaiton.
>
> OBonTopic: BEGIN {print "hello, world"}
>
According to Teds posting, what you posted above is UNIX-specific since
you'd need to escape the quotes for it to work on an MS platform. It
also will only work for some versions of awk. So, by your definition,
your posting is off-topic.
To follow your own rules, please:
a) test every program you post on every possible platform
b) test every program you post using every implementation of awk
c) only post programs that work on every possible platform under every
implementation of awk
d) make sure you never give any hint to a poster about how to invoke
your program on any platform, even when they tell you their platform.
Actually, why not stick to whining about topicality since that, by
definition, is guranteed to be topical and you don't run the risk of
providing any useful but arguably OT information.
Ed.
Post Follow-up to this messageIn article <VfadnWMVRJ07h0ncRVn-tw@comcast.com>, Ed Morton <morton@lsupcaemnt.com> wrote: ... > >According to Teds posting, what you posted above is UNIX-specific since >you'd need to escape the quotes for it to work on an MS platform. It >also will only work for some versions of awk. So, by your definition, >your posting is off-topic. Are you really this stupid or are you just playing that role on the net? What I posted above will work on any AWK, including, yes, Sun's stone age AWK (*) - on any platform. Let me repeat: How you get the AWK code into your interpreter on your platform is your problem, not mine. (*) Yes, in stone age AWK, it will then expect input data as if there was some kind of non-empty set of pattern/action pairs. This problem can be worked around, in various, implementation-specific ways (which are, of course, off-topic)
Post Follow-up to this messageKenny McCormack wrote: > In article <VfadnWMVRJ07h0ncRVn-tw@comcast.com>, > Ed Morton <morton@lsupcaemnt.com> wrote: > ... > > > > Are you really this stupid or are you just playing that role on the net? You constantly post articles whining about topicality, while simultaneously posting articles that by your definition are off-topic, sometimes in the same article. You then resort to name-calling when your inconsistency is pointed out. No doubt your next follow up will be along the lines of "my dad's bigger than your dad". You're just embarassing yourself, son. > What I posted above will work on any AWK, including, yes, Sun's stone age > AWK (*) - on any platform. Let me repeat: How you get the AWK code into > your interpreter on your platform is your problem, not mine. Yes, your problem is apparently far more serious and you have my pity. This is my last posting in this thread on the subject of topicality. Ed. > (*) Yes, in stone age AWK, it will then expect input data as if there was > some kind of non-empty set of pattern/action pairs. This problem can be > worked around, in various, implementation-specific ways (which are, of > course, off-topic) >
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.