http://www.perlmonks.org?node_id=52685

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

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.

      a