Suppose I've a file named "a.txt" and it has 100 lines. Now I want to extract odd lines i.e lines 1,3,5...etc and save them to a different file such as Odd.txt and the same thing for all even lines to save them in the even.txt file keeping the source file as it is.
2 Answers
You can use awk
:
awk '{ print > (NR % 2 ? "odd.txt" : "even.txt") }' a.txt
This reads from a.txt
and appends lines to either odd.txt
or even.txt
depending on the current line number.