Code Comments
Programming Forum and web based access to our favorite programming groups.Hi,
I have written the following awk program, which uses the shell
variables inside the awk program
msg="%s has appeared %s times"
cnt=1
cmd="let cnt=$cnt+1"
optArg[1]="abc"
optArg[2]="def"
num=2
pattern="%s"
rslt=$( echo "$msg" | awk 'BEGIN { x=1;varCnt=1 } { while ( x <= NF ) {
if ( $x == "'$pattern'" ) { print "'${optArg[cnt
]}'";cnt++ } else { print $x } x++ } }' )
echo result is "$rslt"
######Output
result is abc
has
appeared
abc
times
I want the first %s to be replaced by optArg[1], second %s by optArg[2]
& so on.........
Can any one please guide me .......
Thanks in advance
Manjunath
Post Follow-up to this messageXref: newsfeed-west.nntpserver.com comp.lang.awk:24105 Kenny McCormack wrote: <snip> > It has nothing to do with AWK per se. The information that you have > provided is, obviously, OS, shell, and AWK-implementation specific. It's neither OS-specific nor shell-specific. It is awk-implementation-specific with a supporting example in shell. > I don't see that there is anything here, that I have stated, that can > possibly be in a discussable state. Take it over to comp.unix.shell > - they'll be more than happy to accomodate you. Leave it here. We'll be happy to accomodate the OP too. > But just in case you still think the OT trash that you've posted has > anything to do with the AWK language, let me leave you with the following: > > Q) Can I put that trash into a file and run it with (any) AWK interpreter? > A) No. > > Q) Can I put that trash into a file and run it with at least one commonly > available shell (for at least one commonly available OS)? > A) Yes. > > Therefore, it is shell code. Your argument appears to be that anything involving awk arguments is off-topic. That's a little like owning a car with a broken steering column and having your mechanic tell you it's not a car issue because it doesn't involve the engine. Lighten up or feel free to keep telling people their OT. Either way the rest of us will feel free to keep helping them with questions that relate to the awk language, arguments, or implementations. (Call me Einstein) > Not today.... Ed.
Post Follow-up to this messageIn article <1103853694.527510.101090@z14g2000cwz.googlegroups.com>, William James <w_a_x_man@yahoo.com> wrote: ... >On my system, >msg="%s has appeared %s times" >causes an error. > >If this works only on unix-like systems, it should be discussed at >comp.unix.shell. Indeed. Well put, sir.
Post Follow-up to this messageIn article <1104247198. c9ce90fdd1d6081b4c1d43dd9db8275f@teranew s>, Rufus V. Smith <nospam@nospam.com> wrote: % "Patrick TJ McPhee" <ptjm@interlog.com> wrote in message % news:33c7orF3ucabeU1@uni-berlin.de... % > In article <cqia72$neq$1@yin.interaccess.com>, % > Kenny McCormack <gazelle@interaccess.com> wrote: % > % > % I would imagine you could port COMMAND.COM to Unix as well, if the moo d % > % struck you. % > % > It's been done. % Usually a statement like that is followed by some sort of % qualifying reference, be it URL, magazine article, book, % program name. Actually, a statement like that is practically never followed by any sort of qualifying reference at all. The program that I was referring to was called command. I hope this is helpful. -- Patrick TJ McPhee North York Canada ptjm@interlog.com
Post Follow-up to this messageWilliam James wrote: > I am perfectly willing to send posters of DOS questions to > comp.os.msdos. > > However, it seems that the unix hierophants are unwilling > to stop discussing unix issues at great length and to take > it to comp.unix.shell. I am astonished how intolerant one can be. > Let's put it to the test. From now on the rule is > "Don't post solutions that work on only one type of system." > People who come here for Awk information shouldn't People who come here to ask for Awk information will just need to inspect the thread they created. People who inspect every thread out of interest may decide what to read and what to skip by the subject line. > have to separate what they need from a bewildering mass > of details that pertain to an operating system that > is alien and irrelevant to them. Why don't you just ignore threads that are clearly labelled with the keywords _awk_ *and* _shell_? (BTW, it has nothing to do with an "operating system" but rather with the runtime environment; even on a WinDOS operating system you may have installed Cygwin or MKS to run awk in a way the OP has been asking for.) Janis
Post Follow-up to this messageIn article <cqi83l$vk3$1@online.de>, Janis Papanagnou <Janis_Papanagnou@hotmail.com> wrote: ... >I am astonished how intolerant one can be. I'm going to let you in on a little secret: This is all parody. ... >(BTW, it has nothing to do with an "operating system" but rather >with the runtime environment; even on a WinDOS operating system >you may have installed Cygwin or MKS to run awk in a way the OP >has been asking for.) I would imagine you could port COMMAND.COM to Unix as well, if the mood struck you. I think it is fair enough to assume that for most people, in most cases, it is safe to equate the two (I.e., equate using Unix with using some kind of Unix-y shell and equate using MS-dreck OS with using some MS-drecky shell) Note: I've never understood the point of Cygwin/MKS/etc. Why bother? If you want Unix, you know where to find it.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.