in reply to Search and replace in all odd lines
Here's what I mean (the first line uses bash to set up the test case...)
Once you run that, you've got 5 files in the current directory, 1..5, where 1 contains 1 line, and 5 contains 5...for i in 1 2 3 4 5; do perl -e'print "$_\n" foreach 1..$ARGV[0]' $i > +$i;done
This results in:perl -ne'printf "File: $ARGV \$.: %2d real line: $_",$. if $. & 1' 1 2 + 3 4 5
So in file 2 and 3, you get the even lines, because file 1 had an odd # of lines. If we had a file 6, its even lines would get printed instead of the odd ones, since the (1+2+3+4+5) is an odd #.File: 1 $.: 1 : real line: 1 File: 2 $.: 3 : real line: 2 File: 3 $.: 5 : real line: 2 File: 4 $.: 7 : real line: 1 File: 4 $.: 9 : real line: 3 File: 5 $.: 11 : real line: 1 File: 5 $.: 13 : real line: 3 File: 5 $.: 15 : real line: 5
Fun, eh? :)
|
---|