Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

problem w/ print $0 $0
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 )


Report this thread to moderator Post Follow-up to this message
Old Post
coltrane
04-24-05 01:55 PM


Re: problem w/ print $0 $0
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


Report this thread to moderator Post Follow-up to this message
Old Post
coltrane
04-25-05 01:55 AM


Re: problem w/ print $0 $0
thanks,


Report this thread to moderator Post Follow-up to this message
Old Post
coltrane
04-25-05 01:55 AM


Re: problem w/ print $0 $0
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 )


Report this thread to moderator Post Follow-up to this message
Old Post
coltrane
04-25-05 01:55 AM


Re: problem w/ print $0 $0

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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
04-25-05 01:55 AM


Re: problem w/ print $0 $0
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}'


Report this thread to moderator Post Follow-up to this message
Old Post
Loki Harfagr
04-25-05 01:55 AM


Re: problem w/ print $0 $0
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Bill Marcum
04-27-05 01:55 AM


Re: problem w/ print $0 $0
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Bill Marcum
04-27-05 01:55 AM


Re: problem w/ print $0 $0
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ted Davis
04-27-05 08:56 AM


Re: problem w/ print $0 $0
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}'


Report this thread to moderator Post Follow-up to this message
Old Post
Loki Harfagr
04-27-05 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:26 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.