We help IT Professionals succeed at work.

Need to output every second line in a text file

mrbungle50
mrbungle50 asked
on
Hello all,
I need to run a short script of some sort that looks through a text file of a variable sze and take every second line and output this to a new file.
The one catch? is the original file cannot be left with a blank line where the line was extracted
I was looking at a cut -c or maybe an AWK command but can't figure how to gte it to skip a line each time?
the file will be like this:
The quick brown fox jumps over the lazy dog
The slow black dog jumps over the lazy fox
The quick brown fox jumps over the lazy dog
The slow black dog jumps over the lazy fox
The quick brown fox jumps over the lazy dog
The slow black dog jumps over the lazy fox
The quick brown fox jumps over the lazy dog
The slow black dog jumps over the lazy fox
The quick brown fox jumps over the lazy dog
The slow black dog jumps over the lazy fox
The quick brown fox jumps over the lazy dog

I want to have to two files with no blank lines.
One containing "The quick brown fox jumps over the lazy dog" and
the 2nd has "The slow black dog jumps over the lazy fox"
Thanks in advance
Craig
MrBungle50
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
#!/usr/bin/perl
open F1,">One" or die $!;
open F2,">2nd" or die $!;
while( <> ){
    print {$.%2?F1:F2} $_;
}

Author

Commented:
Absolutely fabulous and the syntax makes sense.  I must be learning something from this as I go :-)
Thanks Ozo  you are a champion script writer. I wish you worked in my office.
Thanks again