Remove even numbered lines of text file [duplicate]
Clash Royale CLAN TAG#URR8PPP
This question already has an answer here:
Print odd-numbered lines, print even-numbered lines
7 answers
I have a text file on a Linux system, and would like to remove every second line, which is "even" numbered. Example: I would like to remove the second line of the file, the fourth, sixth, eighth line, and so on, until you complete filtering of the file completely.
file.txt
86850343
88065952
89381968
89536251
89714939
89826424
90124775
90672109
91408453
92438737
I would like this output:
86850343
89381968
89714939
90124775
91408453
text-processing awk sed
marked as duplicate by don_crissti, Sparhawk, terdon♦
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 2 at 2:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Print odd-numbered lines, print even-numbered lines
7 answers
I have a text file on a Linux system, and would like to remove every second line, which is "even" numbered. Example: I would like to remove the second line of the file, the fourth, sixth, eighth line, and so on, until you complete filtering of the file completely.
file.txt
86850343
88065952
89381968
89536251
89714939
89826424
90124775
90672109
91408453
92438737
I would like this output:
86850343
89381968
89714939
90124775
91408453
text-processing awk sed
marked as duplicate by don_crissti, Sparhawk, terdon♦
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 2 at 2:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Print odd-numbered lines, print even-numbered lines
7 answers
I have a text file on a Linux system, and would like to remove every second line, which is "even" numbered. Example: I would like to remove the second line of the file, the fourth, sixth, eighth line, and so on, until you complete filtering of the file completely.
file.txt
86850343
88065952
89381968
89536251
89714939
89826424
90124775
90672109
91408453
92438737
I would like this output:
86850343
89381968
89714939
90124775
91408453
text-processing awk sed
This question already has an answer here:
Print odd-numbered lines, print even-numbered lines
7 answers
I have a text file on a Linux system, and would like to remove every second line, which is "even" numbered. Example: I would like to remove the second line of the file, the fourth, sixth, eighth line, and so on, until you complete filtering of the file completely.
file.txt
86850343
88065952
89381968
89536251
89714939
89826424
90124775
90672109
91408453
92438737
I would like this output:
86850343
89381968
89714939
90124775
91408453
This question already has an answer here:
Print odd-numbered lines, print even-numbered lines
7 answers
text-processing awk sed
text-processing awk sed
edited Jan 2 at 7:52
Rui F Ribeiro
39.5k1479132
39.5k1479132
asked Jan 2 at 0:58
logvcalogvca
313
313
marked as duplicate by don_crissti, Sparhawk, terdon♦
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 2 at 2:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by don_crissti, Sparhawk, terdon♦
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 2 at 2:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
With GNU Sed's n-skip-m
notation:
$ sed '2~2d' file.txt
86850343
89381968
89714939
90124775
91408453
Thanks! Works fine!!!
– logvca
Jan 2 at 1:03
add a comment |
You can't really beat sed
for this sort of thing, but here are some other options:
$ awk 'NR%2!=0' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne '$.%2 && print' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'print if $.%2' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'not $.%2 && print' file
86850343
89381968
89714939
90124775
91408453
2
Heh, the first 3 of those give incorrect output based on the question; the fourth gives the right result :-)
– Stephen Harris
Jan 2 at 1:30
1
@StephenHarris eeeek! Completely fumbled that one. Thanks for the heads up, fixed now.
– terdon♦
Jan 2 at 1:41
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
With GNU Sed's n-skip-m
notation:
$ sed '2~2d' file.txt
86850343
89381968
89714939
90124775
91408453
Thanks! Works fine!!!
– logvca
Jan 2 at 1:03
add a comment |
With GNU Sed's n-skip-m
notation:
$ sed '2~2d' file.txt
86850343
89381968
89714939
90124775
91408453
Thanks! Works fine!!!
– logvca
Jan 2 at 1:03
add a comment |
With GNU Sed's n-skip-m
notation:
$ sed '2~2d' file.txt
86850343
89381968
89714939
90124775
91408453
With GNU Sed's n-skip-m
notation:
$ sed '2~2d' file.txt
86850343
89381968
89714939
90124775
91408453
edited Jan 2 at 1:07
answered Jan 2 at 1:00
steeldriversteeldriver
34.9k35184
34.9k35184
Thanks! Works fine!!!
– logvca
Jan 2 at 1:03
add a comment |
Thanks! Works fine!!!
– logvca
Jan 2 at 1:03
Thanks! Works fine!!!
– logvca
Jan 2 at 1:03
Thanks! Works fine!!!
– logvca
Jan 2 at 1:03
add a comment |
You can't really beat sed
for this sort of thing, but here are some other options:
$ awk 'NR%2!=0' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne '$.%2 && print' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'print if $.%2' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'not $.%2 && print' file
86850343
89381968
89714939
90124775
91408453
2
Heh, the first 3 of those give incorrect output based on the question; the fourth gives the right result :-)
– Stephen Harris
Jan 2 at 1:30
1
@StephenHarris eeeek! Completely fumbled that one. Thanks for the heads up, fixed now.
– terdon♦
Jan 2 at 1:41
add a comment |
You can't really beat sed
for this sort of thing, but here are some other options:
$ awk 'NR%2!=0' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne '$.%2 && print' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'print if $.%2' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'not $.%2 && print' file
86850343
89381968
89714939
90124775
91408453
2
Heh, the first 3 of those give incorrect output based on the question; the fourth gives the right result :-)
– Stephen Harris
Jan 2 at 1:30
1
@StephenHarris eeeek! Completely fumbled that one. Thanks for the heads up, fixed now.
– terdon♦
Jan 2 at 1:41
add a comment |
You can't really beat sed
for this sort of thing, but here are some other options:
$ awk 'NR%2!=0' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne '$.%2 && print' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'print if $.%2' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'not $.%2 && print' file
86850343
89381968
89714939
90124775
91408453
You can't really beat sed
for this sort of thing, but here are some other options:
$ awk 'NR%2!=0' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne '$.%2 && print' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'print if $.%2' file
86850343
89381968
89714939
90124775
91408453
$ perl -ne 'not $.%2 && print' file
86850343
89381968
89714939
90124775
91408453
edited Jan 2 at 1:40
answered Jan 2 at 1:03
terdon♦terdon
129k32253428
129k32253428
2
Heh, the first 3 of those give incorrect output based on the question; the fourth gives the right result :-)
– Stephen Harris
Jan 2 at 1:30
1
@StephenHarris eeeek! Completely fumbled that one. Thanks for the heads up, fixed now.
– terdon♦
Jan 2 at 1:41
add a comment |
2
Heh, the first 3 of those give incorrect output based on the question; the fourth gives the right result :-)
– Stephen Harris
Jan 2 at 1:30
1
@StephenHarris eeeek! Completely fumbled that one. Thanks for the heads up, fixed now.
– terdon♦
Jan 2 at 1:41
2
2
Heh, the first 3 of those give incorrect output based on the question; the fourth gives the right result :-)
– Stephen Harris
Jan 2 at 1:30
Heh, the first 3 of those give incorrect output based on the question; the fourth gives the right result :-)
– Stephen Harris
Jan 2 at 1:30
1
1
@StephenHarris eeeek! Completely fumbled that one. Thanks for the heads up, fixed now.
– terdon♦
Jan 2 at 1:41
@StephenHarris eeeek! Completely fumbled that one. Thanks for the heads up, fixed now.
– terdon♦
Jan 2 at 1:41
add a comment |