1

I want to delete one line on two with linux such that

A
B
C
D
E

becomes

A
D
E

how can I make it work?

1 Answers1

3

It seems to me you want to get every odd line. For this, you can use many tools:

awk 'NR%2' file

this takes into account the number of record (NR, that is, number of line in this case) and evaluates if it is multiple of 2 or not. If it is, the condition NR%2 is false, so that lines are not printed; otherwise, they are. Note the default behaviour of awk is {print $0}, so it can be omitted: 1 is the same as {print $0}.

sed '0~2d' file

Just delete every line that is multiple of 2. You can also inhibit the printing with -n and explicitly print those lines not being multiple of 2:

sed -n '1~2p' file
fedorqui
  • 7,861
  • 7
  • 36
  • 74