For Programmers: Free Programming Magazines  


Home > Archive > AWK > April 2005 > problem w/ print $0 $0









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author problem w/ print $0 $0
coltrane

2005-04-24, 8:55 am

I am having a little problem running a simple awk command.

I need the entire string output twice, but when I try

c:\>dir /b | gawk '{print $0 " " $0}'

if only get one output item

This is using cygwin's gawk on a windows box ( excuse the 'w' word )

coltrane

2005-04-24, 8:55 pm

Janis,
thanks but this also does not work.

this is a simple example of what is happening:


C:\BIN>echo one two | gawk '{print $1 " " $2}'
one two

C:\BIN>echo one two | gawk '{print $1 " " $1}'
one one

C:\BIN>echo one two | gawk '{print $0 " " $0}'
one two

the last command I would expect to be:
one two one two

coltrane

2005-04-24, 8:55 pm

thanks,

coltrane

2005-04-24, 8:55 pm

I have always had success with the quotes I used. But just to give it a
try:

c:\>echo one two | gawk "{print $0 ' ' $0}"
gawk: {print $0 ' ' $0}
gawk: ^ invalid char ''' in expression


so here is some other output


c:\>echo one two | gawk '{print $0" some stuff " $0}'
some stuff one two

c:\>echo one two | gawk '{print $1" some stuff " $1}'
one some stuff one

c:\>echo one two | gawk '{print $1" some stuff " $2}'
one some stuff two


now the next 2 are a little interesting

c:\>echo one two | gawk '{print $0 " some stuff"}'
some stuff

c:\>echo one two | gawk '{print " some stuff " $0}'
some stuff one two

oh well just one of those windows thingies
works fine on linux ( no surprise there )

Ed Morton

2005-04-24, 8:55 pm



coltrane wrote:

> I have always had success with the quotes I used. But just to give it a
> try:
>
> c:\>echo one two | gawk "{print $0 ' ' $0}"
> gawk: {print $0 ' ' $0}
> gawk: ^ invalid char ''' in expression


> c:\>echo one two | gawk '{print $0" some stuff " $0}'
> some stuff one two
>
> c:\>echo one two | gawk '{print $1" some stuff " $1}'
> one some stuff one
>
> c:\>echo one two | gawk '{print $1" some stuff " $2}'
> one some stuff two


> c:\>echo one two | gawk '{print $0 " some stuff"}'
> some stuff
>
> c:\>echo one two | gawk '{print " some stuff " $0}'
> some stuff one two



Will you PLEASE just do what Janis suggested days ago instead of
repeating all this nonsense that obviously will not work!!!!!

Ed.
Loki Harfagr

2005-04-24, 8:55 pm

Le Fri, 22 Apr 2005 04:53:09 -0700, coltrane a écrit_:

> Janis,
> thanks but this also does not work.
>
> this is a simple example of what is happening:
>
>
> C:\BIN>echo one two | gawk '{print $1 " " $2}'
> one two
>
> C:\BIN>echo one two | gawk '{print $1 " " $1}'
> one one
>
> C:\BIN>echo one two | gawk '{print $0 " " $0}'
> one two
>
> the last command I would expect to be:
> one two one two


It should :-)

Try without the spaces maybe ?
$ echo one two | gawk '{print $0" "$0}'

Bill Marcum

2005-04-26, 8:55 pm

On 21 Apr 2005 13:52:59 -0700, coltrane
<tendengarci@yahoo.com> wrote:
> I am having a little problem running a simple awk command.
>
> I need the entire string output twice, but when I try
>
> c:\>dir /b | gawk '{print $0 " " $0}'
>

I bet it's that darn CRLF thing again.
In other words, you are only seeing $0 one time because gawk is printing
$0\r" "$0

dir /b | gawk '{sub(/\r/,""); print $0 " " $0}'

--
Chisolm's First Corollary to Murphy's Second Law:
When things just can't possibly get any worse, they will.
Bill Marcum

2005-04-26, 8:55 pm

On 22 Apr 2005 10:09:54 -0700, coltrane
<tendengarci@yahoo.com> wrote:
> I have always had success with the quotes I used. But just to give it a
> try:
>
> c:\>echo one two | gawk "{print $0 ' ' $0}"
> gawk: {print $0 ' ' $0}
> gawk: ^ invalid char ''' in expression
>

echo one two | gawk "{print $0 \" \" $0}"



--
Chisolm's First Corollary to Murphy's Second Law:
When things just can't possibly get any worse, they will.
Ted Davis

2005-04-27, 3:56 am

On Fri, 22 Apr 2005 01:53:45 GMT, gazelle@yin.interaccess.com (Kenny
McCormack) wrote:

>In article <1gkg61dca5urfgnc3kh3s627sb5ab50pe0@4ax.com>,
>Ted Davis <tdavis@gearbox.maem.umr.edu> wrote:
> ^^^^
>
>What do you mean by "true" in this context?


Compiled with a Windows compiler, perhaps with specific modifications
for use in the Windows console environment. The Cygwin version is
intended for use in the Cygwin environment though it does seem to work
in the pure Windows environment (Cygwin is installed and configured
for DOS style files). I seem to remember that they fail differently
when asked to do Unix specific things like bidirectional pipes and
direct read/write to TCP/IP, though they both fail.


--
T.E.D. (tdavis@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.
Loki Harfagr

2005-04-27, 3:56 am

Le Fri, 22 Apr 2005 04:53:09 -0700, coltrane a écrit_:

> Janis,
> thanks but this also does not work.
>
> this is a simple example of what is happening:
>
>
> C:\BIN>echo one two | gawk '{print $1 " " $2}'
> one two
>
> C:\BIN>echo one two | gawk '{print $1 " " $1}'
> one one
>
> C:\BIN>echo one two | gawk '{print $0 " " $0}'
> one two
>
> the last command I would expect to be:
> one two one two


It should :-)

Try without the spaces maybe ?
$ echo one two | gawk '{print $0" "$0}'

Janis Papanagnou

2005-04-27, 3:56 am

[ Please quote context! ]

coltrane wrote:
> Janis,
> thanks but this also does not work.


What "this" are you talking about.

> this is a simple example of what is happening:
>
>
> C:\BIN>echo one two | gawk '{print $1 " " $2}'
> one two
>
> C:\BIN>echo one two | gawk '{print $1 " " $1}'
> one one
>
> C:\BIN>echo one two | gawk '{print $0 " " $0}'
> one two
>
> the last command I would expect to be:
> one two one two


All three calls do not match what I suggested to try out; re-read what
I had written...[color=darkred]

Janis
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com