in reply to Editing just one column in a file

perl -lane '++$F[15]; print join "\t", @F' file

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Editing just one column in a file
by ZWcarp (Beadle) on Nov 28, 2011 at 22:14 UTC

    Ahhh ok brilliant. One more question.. why does this only print one column instead of the specified array range?I'm sure I'm doing something stupid but I can't find a good website or text with detailed stuff on specific command line perl

    perl -lane '$,="\t";print $F[0..6]'  file.txt Thanks so much!

    UPDATE Sorry, I got it, you just need to change the $ to a @ in front of F. Apologies

Re^2: Editing just one column in a file
by vinian (Beadle) on Nov 29, 2011 at 02:04 UTC
    hi, i am confused about this, need your help.
    echo "Just another perl monkers " | perl -lane 'print $F[0..3]'
    Output:
    Just
    why it treat $F[0..3] as $F[0] but not $F[1]or $F[2]or $F[3].

      Because the Perl syntax for an array slice is @a[ ... ].

      If you enable warnings, you'll see that by using $a[1..3], the 1..3 is treated as a flip-flop operator comparing against $., and under most circumstances will produce false, which in the numeric context gets taken as 0:

      c:\test>perl -wE"@a = 0..10; say $a[1..3]; say @a[1..3]" Use of uninitialized value in range (or flip) at -e line 1. Argument "" isn't numeric in array element at -e line 1. 0 123

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Why is it that this

         perl -lane '$,="\t"; print @F[0..4] ."\t\t\t" . @F[25..30]' file.txt

        Does not do what I intended ( for the ranges to be printed by tabs, followed by three blank columns followed by another range). Thankyou for your help!

        thanks, but i got something more strange
        vinian@cc:~$ echo "Just another perl monker" | perl -w -lane 'print $F +[0..3]' Argument "" isn't numeric in array element at -e line 1, <> line 1. Just vinian@cc:~$ echo "Just another perl monker" | perl -w -lane 'print $F +[1..3]' another vinian@cc:~$ echo "Just another perl monker" | perl -w -lane 'print $F +[2..3]' Argument "" isn't numeric in array element at -e line 1, <> line 1. Just vinian@cc:~$ echo "Just another perl monker" | perl -w -lane 'print $F +[3..3]' Argument "" isn't numeric in array element at -e line 1, <> line 1. Just

        when $F[1..3] there is no warnings and the output is $F[1]