Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

chomp a newline in awk

by Anonymous Monk
on Jan 18, 2001 at 07:55 UTC ( #52685=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

EZ question how do you chomp a newline in awk

Comment on chomp a newline in awk
Re (tilly) 1: chomp a newline in awk
by tilly (Archbishop) on Jan 18, 2001 at 08:20 UTC
    Run a2p to convert to a less awk-ward language, then do it in Perl with chomp...
Re: chomp a newline in awk
by eg (Friar) on Jan 18, 2001 at 08:25 UTC

    Ewww. awk.

    gsub( "\n", "" );

    will remove all newlines in $0, if that's what you're looking for. I suppose you could anchor it with $

    gsub( /\n$/, "" );

    to be more like chomp.

    update: Oops! Looks like a is right. I based my assertion on the fact that

    % cat foo | awk '{ gsub(/\n$/,""); printf("%s", $0); }'

    printed out foo as a single line. But take out the gsub and you're okay too. Oh well.

      Doesn't awk (nawk) automatically chomp? 'least-wise, all my scripts (whoops - old scripts, really ;-) never worry about it: print adds \n back automatically.

      a

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://52685]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-11-27 16:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (186 votes), past polls