sed (GNU)
Com (GNU) sed
:
sed '0~2G'
Curto (feio para N = 100):
sed 'n;G'
man sed explica como:
first ~ step
Match every step'th line starting with line first. For example, ''sed -n 1~2p'' will print all the odd-numbered lines in the input stream, and the address 2~5 will match every fifth line, starting with the second. first can be zero; in this case, sed operates as if it were equal to step. (This is an extension.)
sed (outro)
Com outro sed (contar novas linhas):
sed -e 'p;s/.*//;H;x;/\n\{2\}/{g;p};x;d'
Ou, para ser mais portátil, escrito como (remova comentários para algumas versões do sed):
sed -e ' # Start a sed script.
p # Whatever happens later, print the line.
s/.*// # Clean the pattern space.
H # Add **one** newline to hold space.
x # Get the hold space to examine it, now is empty.
/\n\{2\}/{ # Test if there are 2 new lines counted.
g # Erase the newline count.
p # Print an additional new line.
} # End the test.
x # match the 'x' done above.
d # don't print anything else. Re-start.
' # End sed script.
awk
Com awk
, provavelmente:
awk '1 ; NR%2==0 {printf"\n"} '