Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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

Replies are listed 'Best First'.
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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://52685]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2018-03-23 01:39 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (287 votes). Check out past polls.