Is it possible to filter a set of lines through an external command in ed?

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
In ed, one can retrieve the output of a command into the current buffer by using r !COMMAND. One can also write a set of lines to the input of a command by using 1,3w !COMMAND.
However, I cannot determine how to do both simultaneously.
r 1,3w !sort
1,3w !sort: No such file or directory
Is it possible to do this in ed?
ed
add a comment |Â
up vote
1
down vote
favorite
In ed, one can retrieve the output of a command into the current buffer by using r !COMMAND. One can also write a set of lines to the input of a command by using 1,3w !COMMAND.
However, I cannot determine how to do both simultaneously.
r 1,3w !sort
1,3w !sort: No such file or directory
Is it possible to do this in ed?
ed
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
In ed, one can retrieve the output of a command into the current buffer by using r !COMMAND. One can also write a set of lines to the input of a command by using 1,3w !COMMAND.
However, I cannot determine how to do both simultaneously.
r 1,3w !sort
1,3w !sort: No such file or directory
Is it possible to do this in ed?
ed
In ed, one can retrieve the output of a command into the current buffer by using r !COMMAND. One can also write a set of lines to the input of a command by using 1,3w !COMMAND.
However, I cannot determine how to do both simultaneously.
r 1,3w !sort
1,3w !sort: No such file or directory
Is it possible to do this in ed?
ed
asked May 18 at 17:47
merlin2011
1,58431422
1,58431422
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
how to do both simultaneously
You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.ed was clearly not designed to do that kind of stuff... Try vim.
That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:
ed -s infile
5,8d
4r ! ed -s infile<<<$'5,8w !sort -nnq'
,p
q
add a comment |Â
up vote
0
down vote
The only way I found to do this requires using an external file to store the results temporarily.
$ cat input.txt
13
5
29
22
45
64
17
20
69
91
$ ed input.txt
29
1,3w !sort -n > temp.txt
8
1,3d
0r temp.txt
8
wq
29
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
how to do both simultaneously
You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.ed was clearly not designed to do that kind of stuff... Try vim.
That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:
ed -s infile
5,8d
4r ! ed -s infile<<<$'5,8w !sort -nnq'
,p
q
add a comment |Â
up vote
1
down vote
how to do both simultaneously
You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.ed was clearly not designed to do that kind of stuff... Try vim.
That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:
ed -s infile
5,8d
4r ! ed -s infile<<<$'5,8w !sort -nnq'
,p
q
add a comment |Â
up vote
1
down vote
up vote
1
down vote
how to do both simultaneously
You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.ed was clearly not designed to do that kind of stuff... Try vim.
That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:
ed -s infile
5,8d
4r ! ed -s infile<<<$'5,8w !sort -nnq'
,p
q
how to do both simultaneously
You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.ed was clearly not designed to do that kind of stuff... Try vim.
That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:
ed -s infile
5,8d
4r ! ed -s infile<<<$'5,8w !sort -nnq'
,p
q
answered May 18 at 23:03
don_crissti
46.2k15121151
46.2k15121151
add a comment |Â
add a comment |Â
up vote
0
down vote
The only way I found to do this requires using an external file to store the results temporarily.
$ cat input.txt
13
5
29
22
45
64
17
20
69
91
$ ed input.txt
29
1,3w !sort -n > temp.txt
8
1,3d
0r temp.txt
8
wq
29
add a comment |Â
up vote
0
down vote
The only way I found to do this requires using an external file to store the results temporarily.
$ cat input.txt
13
5
29
22
45
64
17
20
69
91
$ ed input.txt
29
1,3w !sort -n > temp.txt
8
1,3d
0r temp.txt
8
wq
29
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The only way I found to do this requires using an external file to store the results temporarily.
$ cat input.txt
13
5
29
22
45
64
17
20
69
91
$ ed input.txt
29
1,3w !sort -n > temp.txt
8
1,3d
0r temp.txt
8
wq
29
The only way I found to do this requires using an external file to store the results temporarily.
$ cat input.txt
13
5
29
22
45
64
17
20
69
91
$ ed input.txt
29
1,3w !sort -n > temp.txt
8
1,3d
0r temp.txt
8
wq
29
answered May 18 at 18:00
merlin2011
1,58431422
1,58431422
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
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%2funix.stackexchange.com%2fquestions%2f444670%2fis-it-possible-to-filter-a-set-of-lines-through-an-external-command-in-ed%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
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');
);
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');
);
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