Hello
How can I print a "#" with gawk?
Thank
=========================================================================== Patrick DUPRÉ | | email: pdupre@gmx.com 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 ===========================================================================
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: pdupre@gmx.com 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" samuel@sieb.net To: users@lists.fedoraproject.org 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 -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org
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.
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 ricks@alldigital.com - - 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) - ----------------------------------------------------------------------
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.
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
On Wed, May 16, 2018, 18:52 Patrick O'Callaghan pocallaghan@gmail.com 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 -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.or users-leave@lists.fedoraproject.org
Im kind of old fashioned, I use printf.
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: pdupre@gmx.com
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: pdupre@gmx.com 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" fedora@eyal.emu.id.au To: users@lists.fedoraproject.org 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: pdupre@gmx.com
-- Eyal Lebedinsky (fedora@eyal.emu.id.au) _______________________________________________ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org