0

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.

0
4

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.

0
0

With sed:

sed -ne 'w odd.txt' -e 'n; w even.txt' a.txt

Not the answer you're looking for? Browse other questions tagged or ask your own question.