Odd-Even file partitionning using sed and awk
I had to run a simulation and because I was printing the internal state of my system and the observed state, I had to separate both in 2 files.
./simulation | sed '1d;$d' | awk 'NR%2==1 {print > "odd_lines.txt"; next} {print > "even_lines.txt"}'
-
sed '1d;$d':-
1ddeletes the first line -
$ddeletes the last line
-
-
awk 'NR%2==1 {print > "odd_lines.txt"; next} {print > "even_lines.txt"}':-
NR%2==1current line number (Number of Record) mod 2
-
Enjoy Reading This Article?
Here are some more articles you might like to read next: