in reply to Re: One liner to S & R by column
in thread One liner to S & R by column

If $. is 0 (first line of the file), skip to the next iteration. … On all subsequent iterations $. will no longer be zero…

The number of the first line of the input file is 1, not 0. So you need to use an explicit comparison operation.

perl -pli.bak -e 'substr($_, 18, 1) =~ tr/Y/H/ if $. > 1' filename

Here's the same thing using a regular expression.

perl -pli.bak -e 's/^.{18}\KY/H/ if $. > 1' filename

Jim

Replies are listed 'Best First'.
Re^3: One liner to S & R by column
by davido (Cardinal) on Dec 23, 2013 at 18:01 UTC

    Updated (and documented the change). :) Thanks.


    Dave

      Hi,

      you still have this sentence in your original post:

      "On all subsequent iterations $. will no longer be zero." You will probably want to fix it.