in reply to One liner to S & R by column

What have you tried?

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

Here's how to read it:

perlrun, perlintro, and perlop should contain 99% of what you need to learn to get a good start on the next one-liner yourself.

Update: Added play by play explanation.

Update2: Fixed issue where files aren't zero-indexed with respect to $. (Thanks Jim,Laurent_R)


Dave

Replies are listed 'Best First'.
Re^2: One liner to S & R by column
by Jim (Curate) on Dec 23, 2013 at 17:54 UTC
    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

      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.

Re^2: One liner to S & R by column
by dirtdog (Monk) on Dec 23, 2013 at 17:15 UTC

    Thank you Dave. That worked like a charm!