gawk

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

gawk

Patrick Dupre-4
Hello

How can I print a "#" with gawk?

Thank

===========================================================================
 Patrick DUPRÉ                                 | | email: [hidden email]
 Laboratoire de Physico-Chimie de l'Atmosphère | |
 Université du Littoral-Côte d'Opale           | |
 Tel.  (33)-(0)3 28 23 76 12                   | | Fax: 03 28 65 82 44
 189A, avenue Maurice Schumann                 | | 59140 Dunkerque, France
===========================================================================
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: gawk

Samuel Sieb
On 05/16/2018 01:53 PM, Patrick Dupre wrote:
> How can I print a "#" with gawk?

Some more context would help, but
gawk -e '{print "#" }'
works.
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: gawk

Patrick Dupre-4
Sorry,

This is correct, but
if I do:
          print "#" > "tmptmp.txt" ;
after
print $1 $2 > "tmptmp.txt" ;

then I get ^M
in my file
I do not have the ^M  if I only make print $1 $2 > "tmptmp.txt" ;
and never make a print "#"

Can I avoid these ^M
?

Thank.

===========================================================================
 Patrick DUPRÉ                                 | | email: [hidden email]
 Laboratoire de Physico-Chimie de l'Atmosphère | |
 Université du Littoral-Côte d'Opale           | |
 Tel.  (33)-(0)3 28 23 76 12                   | | Fax: 03 28 65 82 44
 189A, avenue Maurice Schumann                 | | 59140 Dunkerque, France
===========================================================================


> Sent: Wednesday, May 16, 2018 at 10:58 PM
> From: "Samuel Sieb" <[hidden email]>
> To: [hidden email]
> Subject: Re: gawk
>
> On 05/16/2018 01:53 PM, Patrick Dupre wrote:
> > How can I print a "#" with gawk?
>
> Some more context would help, but
> gawk -e '{print "#" }'
> works.
> _______________________________________________
> users mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
>
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: gawk

Samuel Sieb
On 05/16/2018 02:05 PM, Patrick Dupre wrote:

> This is correct, but
> if I do:
>  print "#" > "tmptmp.txt" ;
> after
> print $1 $2 > "tmptmp.txt" ;
>
> then I get ^M
> in my file
> I do not have the ^M  if I only make print $1 $2 > "tmptmp.txt" ;
> and never make a print "#"
>
> Can I avoid these ^M
> ?

This really isn't the right place for this kind of question, but at
least provide a full example of what you're trying to do.  You aren't
providing enough info to get a useful response.
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: gawk

Rick Stevens-3
On 05/16/2018 02:11 PM, Samuel Sieb wrote:

> On 05/16/2018 02:05 PM, Patrick Dupre wrote:
>> This is correct, but
>> if I do:
>>       print "#" > "tmptmp.txt" ;
>> after
>> print $1 $2 > "tmptmp.txt" ;
>>
>> then I get ^M
>> in my file
>> I do not have the ^M  if I only make print $1 $2 > "tmptmp.txt" ;
>> and never make a print "#"
>>
>> Can I avoid these ^M
>> ?
>
> This really isn't the right place for this kind of question, but at
> least provide a full example of what you're trying to do.  You aren't
> providing enough info to get a useful response.

I agree with Sam that you aren't providing enough info. I think
you're saying you're essentially doing (in gawk):

        print $1 $2 > "tmptmp.txt";
        print "#" > "tmptmp.txt";

And ending up with a "^M" in your file. First off, the second line
would overwrite anything you did in the first line (you need to use a
">>" to APPEND data to an existing file...just like in the shell), and
the "^M" probably indicates a carriage return in the file. If you
changed the ORS (output record separator) to a carriage return from it's
default value of newline, that's what you'd get.

Patrick, this isn't the first time (or second or third) you've posted
a question with absolutely no context about what you're trying to do.
If you want help, you HAVE to tell us what you're trying to accomplish.
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer, AllDigital    [hidden email] -
- AIM/Skype: therps2        ICQ: 22643734            Yahoo: origrps2 -
-                                                                    -
-    Admitting you have a problem is the first step toward getting   -
-    medicated for it.      -- Jim Evarts (http://www.TopFive.com)   -
----------------------------------------------------------------------
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: gawk

Jon LaBadie
On Wed, May 16, 2018 at 02:43:09PM -0700, Rick Stevens wrote:

> On 05/16/2018 02:11 PM, Samuel Sieb wrote:
> > On 05/16/2018 02:05 PM, Patrick Dupre wrote:
> >> This is correct, but
> >> if I do:
> >>       print "#" > "tmptmp.txt" ;
> >> after
> >> print $1 $2 > "tmptmp.txt" ;
> >>
> >> then I get ^M
> >> in my file
> >> I do not have the ^M  if I only make print $1 $2 > "tmptmp.txt" ;
> >> and never make a print "#"
> >>
> >> Can I avoid these ^M
> >> ?
> >
> > This really isn't the right place for this kind of question, but at
> > least provide a full example of what you're trying to do.  You aren't
> > providing enough info to get a useful response.
>
> I agree with Sam that you aren't providing enough info. I think
> you're saying you're essentially doing (in gawk):
>
> print $1 $2 > "tmptmp.txt";
> print "#" > "tmptmp.txt";

True in shell, not in awk.  If the file names match,
only the first encountered '>' overwrites the file.
The ">>" is needed to avoid overwriting a file that
exists at the start of the program (like a logfile).

>
> And ending up with a "^M" in your file. First off, the second line
> would overwrite anything you did in the first line (you need to use a
> ">>" to APPEND data to an existing file...just like in the shell), and
> the "^M" probably indicates a carriage return in the file. If you
> changed the ORS (output record separator) to a carriage return from it's
> default value of newline, that's what you'd get.
>

I just noted the output file name with a ".txt" extension.
Might gawk assume this is a "windows text file" and add
a \r instead of \n?

Try a different output file name.

> Patrick, this isn't the first time (or second or third) you've posted
> a question with absolutely no context about what you're trying to do.
> If you want help, you HAVE to tell us what you're trying to accomplish.

--
Jon H. LaBadie                  [hidden email]
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: gawk

Patrick O'Callaghan
In reply to this post by Rick Stevens-3
On Wed, 2018-05-16 at 14:43 -0700, Rick Stevens wrote:
> Patrick, this isn't the first time (or second or third) you've posted
> a question with absolutely no context about what you're trying to do.
> If you want help, you HAVE to tell us what you're trying to accomplish.

And maybe once in a while use a subject line with more than one word.
Just saying ...

poc
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: gawk

Terry Polzin-2


On Wed, May 16, 2018, 18:52 Patrick O'Callaghan <[hidden email]> wrote:
On Wed, 2018-05-16 at 14:43 -0700, Rick Stevens wrote:
> Patrick, this isn't the first time (or second or third) you've posted
> a question with absolutely no context about what you're trying to do.
> If you want help, you HAVE to tell us what you're trying to accomplish.

And maybe once in a while use a subject line with more than one word.
Just saying ...

poc
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Im kind of old fashioned, I use printf.


_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: gawk

Eyal Lebedinsky
In reply to this post by Patrick Dupre-4
On 17/05/18 07:05, Patrick Dupre wrote:

> Sorry,
>
> This is correct, but
> if I do:
>  print "#" > "tmptmp.txt" ;
> after
> print $1 $2 > "tmptmp.txt" ;
>
> then I get ^M
> in my file
> I do not have the ^M  if I only make print $1 $2 > "tmptmp.txt" ;
> and never make a print "#"
>
> Can I avoid these ^M
> ?

I ran this test:

$ rm "tmptmp.txt"
$ echo a b c d | gawk '{print $1 $2 > "tmptmp.txt" ; print "#" > "tmptmp.txt"}'

And then got the correct output:

$ cat tmptmp.txt
ab
#

You need to show exactly what you did, like
- what command did you run?
- how did you examine the output file?

A console transcript will be a good start.

HTH

> Thank.
>
> ===========================================================================
>   Patrick DUPRÉ                                 | | email: [hidden email]

--
Eyal Lebedinsky ([hidden email])
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: gawk

Patrick Dupre-4
Dear all,

I am sorry for my mistake, and I wish to thank every body for the suggestions.

My mistake came from the fact that my original file (containing the
variables $1 and $2), had been generated by a windows system.
Then the ^M where propagated from file to file when I used
print "#" >
and not when I did not used this print.

Weird.

===========================================================================
 Patrick DUPRÉ                                 | | email: [hidden email]
 Laboratoire de Physico-Chimie de l'Atmosphère | |
 Université du Littoral-Côte d'Opale           | |
 Tel.  (33)-(0)3 28 23 76 12                   | | Fax: 03 28 65 82 44
 189A, avenue Maurice Schumann                 | | 59140 Dunkerque, France
===========================================================================


> Sent: Thursday, May 17, 2018 at 2:35 AM
> From: "Eyal Lebedinsky" <[hidden email]>
> To: [hidden email]
> Subject: Re: gawk
>
> On 17/05/18 07:05, Patrick Dupre wrote:
> > Sorry,
> >
> > This is correct, but
> > if I do:
> >  print "#" > "tmptmp.txt" ;
> > after
> > print $1 $2 > "tmptmp.txt" ;
> >
> > then I get ^M
> > in my file
> > I do not have the ^M  if I only make print $1 $2 > "tmptmp.txt" ;
> > and never make a print "#"
> >
> > Can I avoid these ^M
> > ?
>
> I ran this test:
>
> $ rm "tmptmp.txt"
> $ echo a b c d | gawk '{print $1 $2 > "tmptmp.txt" ; print "#" > "tmptmp.txt"}'
>
> And then got the correct output:
>
> $ cat tmptmp.txt
> ab
> #
>
> You need to show exactly what you did, like
> - what command did you run?
> - how did you examine the output file?
>
> A console transcript will be a good start.
>
> HTH
>
> > Thank.
> >
> > ===========================================================================
> >   Patrick DUPRÉ                                 | | email: [hidden email]
>
> --
> Eyal Lebedinsky ([hidden email])
> _______________________________________________
> users mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
>
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@.../message/S65ZWOMFM5NXP2LRC7GEGF2Q4ZGOZZ5T/