Cut specific lines of a file and paste them at the end of another file
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
0
down vote
favorite
Suppose I want to cut more than one interval of lines from one file (eg., lines 1-500, 1029-1729 and 2696-3446), appending values at the end of another file (output.txt) and eliminating these values from the first file. The origin is a file with 9277 lines, I want to cut some of them, eliminating them from the original file and pasting them into another file. Is that possible via command line?
command-line text-processing
add a comment |Â
up vote
0
down vote
favorite
Suppose I want to cut more than one interval of lines from one file (eg., lines 1-500, 1029-1729 and 2696-3446), appending values at the end of another file (output.txt) and eliminating these values from the first file. The origin is a file with 9277 lines, I want to cut some of them, eliminating them from the original file and pasting them into another file. Is that possible via command line?
command-line text-processing
3
Example input and output, please.
â muru
May 29 at 8:41
Is my improvement in the problem description enough?
â Anselmo Ferreira
May 29 at 8:51
unix.stackexchange.com/questions/47407/â¦
â M. Becerra
May 29 at 9:02
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Suppose I want to cut more than one interval of lines from one file (eg., lines 1-500, 1029-1729 and 2696-3446), appending values at the end of another file (output.txt) and eliminating these values from the first file. The origin is a file with 9277 lines, I want to cut some of them, eliminating them from the original file and pasting them into another file. Is that possible via command line?
command-line text-processing
Suppose I want to cut more than one interval of lines from one file (eg., lines 1-500, 1029-1729 and 2696-3446), appending values at the end of another file (output.txt) and eliminating these values from the first file. The origin is a file with 9277 lines, I want to cut some of them, eliminating them from the original file and pasting them into another file. Is that possible via command line?
command-line text-processing
edited May 29 at 8:49
asked May 29 at 8:34
![](https://i.stack.imgur.com/NJljy.png?s=32&g=1)
![](https://i.stack.imgur.com/NJljy.png?s=32&g=1)
Anselmo Ferreira
1285
1285
3
Example input and output, please.
â muru
May 29 at 8:41
Is my improvement in the problem description enough?
â Anselmo Ferreira
May 29 at 8:51
unix.stackexchange.com/questions/47407/â¦
â M. Becerra
May 29 at 9:02
add a comment |Â
3
Example input and output, please.
â muru
May 29 at 8:41
Is my improvement in the problem description enough?
â Anselmo Ferreira
May 29 at 8:51
unix.stackexchange.com/questions/47407/â¦
â M. Becerra
May 29 at 9:02
3
3
Example input and output, please.
â muru
May 29 at 8:41
Example input and output, please.
â muru
May 29 at 8:41
Is my improvement in the problem description enough?
â Anselmo Ferreira
May 29 at 8:51
Is my improvement in the problem description enough?
â Anselmo Ferreira
May 29 at 8:51
unix.stackexchange.com/questions/47407/â¦
â M. Becerra
May 29 at 9:02
unix.stackexchange.com/questions/47407/â¦
â M. Becerra
May 29 at 9:02
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
Using sed, you can write a set of lines to a different file while deleting it from the current file like so:
sed -i -e 'N, M w output.txt
d ' input.txt
where N
and M
are the line numbers. The -i
option makes sed
save changes to the source file, and here the d
command deletes to those lines. At the same time, w output.txt
causes the selected lines to be written to output.txt
. And yes, those are two separate lines: sed
requires that the w
command's filename be till a newline.
So you can do something like:
cmd=' w output.txt
d '
sed -i -e "1,500 $cmd" -e "1029,1729 $cmd" -e "2696,3446 $cmd" input.txt
add a comment |Â
up vote
1
down vote
possible !
copy lines to
dest.file
with redirected outout ofgrep 'pattern' src.file >> dest.file
delete lines from
src.file
withsed -i '/pattern/d' src.file
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Using sed, you can write a set of lines to a different file while deleting it from the current file like so:
sed -i -e 'N, M w output.txt
d ' input.txt
where N
and M
are the line numbers. The -i
option makes sed
save changes to the source file, and here the d
command deletes to those lines. At the same time, w output.txt
causes the selected lines to be written to output.txt
. And yes, those are two separate lines: sed
requires that the w
command's filename be till a newline.
So you can do something like:
cmd=' w output.txt
d '
sed -i -e "1,500 $cmd" -e "1029,1729 $cmd" -e "2696,3446 $cmd" input.txt
add a comment |Â
up vote
3
down vote
accepted
Using sed, you can write a set of lines to a different file while deleting it from the current file like so:
sed -i -e 'N, M w output.txt
d ' input.txt
where N
and M
are the line numbers. The -i
option makes sed
save changes to the source file, and here the d
command deletes to those lines. At the same time, w output.txt
causes the selected lines to be written to output.txt
. And yes, those are two separate lines: sed
requires that the w
command's filename be till a newline.
So you can do something like:
cmd=' w output.txt
d '
sed -i -e "1,500 $cmd" -e "1029,1729 $cmd" -e "2696,3446 $cmd" input.txt
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Using sed, you can write a set of lines to a different file while deleting it from the current file like so:
sed -i -e 'N, M w output.txt
d ' input.txt
where N
and M
are the line numbers. The -i
option makes sed
save changes to the source file, and here the d
command deletes to those lines. At the same time, w output.txt
causes the selected lines to be written to output.txt
. And yes, those are two separate lines: sed
requires that the w
command's filename be till a newline.
So you can do something like:
cmd=' w output.txt
d '
sed -i -e "1,500 $cmd" -e "1029,1729 $cmd" -e "2696,3446 $cmd" input.txt
Using sed, you can write a set of lines to a different file while deleting it from the current file like so:
sed -i -e 'N, M w output.txt
d ' input.txt
where N
and M
are the line numbers. The -i
option makes sed
save changes to the source file, and here the d
command deletes to those lines. At the same time, w output.txt
causes the selected lines to be written to output.txt
. And yes, those are two separate lines: sed
requires that the w
command's filename be till a newline.
So you can do something like:
cmd=' w output.txt
d '
sed -i -e "1,500 $cmd" -e "1029,1729 $cmd" -e "2696,3446 $cmd" input.txt
answered May 29 at 9:20
muru
128k19270460
128k19270460
add a comment |Â
add a comment |Â
up vote
1
down vote
possible !
copy lines to
dest.file
with redirected outout ofgrep 'pattern' src.file >> dest.file
delete lines from
src.file
withsed -i '/pattern/d' src.file
add a comment |Â
up vote
1
down vote
possible !
copy lines to
dest.file
with redirected outout ofgrep 'pattern' src.file >> dest.file
delete lines from
src.file
withsed -i '/pattern/d' src.file
add a comment |Â
up vote
1
down vote
up vote
1
down vote
possible !
copy lines to
dest.file
with redirected outout ofgrep 'pattern' src.file >> dest.file
delete lines from
src.file
withsed -i '/pattern/d' src.file
possible !
copy lines to
dest.file
with redirected outout ofgrep 'pattern' src.file >> dest.file
delete lines from
src.file
withsed -i '/pattern/d' src.file
answered May 29 at 9:04
cmak.fr
1,529918
1,529918
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1041487%2fcut-specific-lines-of-a-file-and-paste-them-at-the-end-of-another-file%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
Example input and output, please.
â muru
May 29 at 8:41
Is my improvement in the problem description enough?
â Anselmo Ferreira
May 29 at 8:51
unix.stackexchange.com/questions/47407/â¦
â M. Becerra
May 29 at 9:02