Use sed to print selected lines within a range
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Consider the simplified file
AAA
BBB
CCC1
DDD
EEE
CCC2
DDD
FFF
GGG
CCC3
HHH
I can pick out the range EEE
to FFF
with
sed -n '/EEE/,/FFF/p'
Suppose though that I want to print any line containing C
but only within the matching range. I can pipe the result from sed
through grep
sed -n '/EEE/,/FFF/p' | grep 'C'
I could also do the range and match in a little awk
script (or perl
, python
, etc.). But how would I do this using just one invocation of sed
?
sed pattern-matching
add a comment |Â
up vote
1
down vote
favorite
Consider the simplified file
AAA
BBB
CCC1
DDD
EEE
CCC2
DDD
FFF
GGG
CCC3
HHH
I can pick out the range EEE
to FFF
with
sed -n '/EEE/,/FFF/p'
Suppose though that I want to print any line containing C
but only within the matching range. I can pipe the result from sed
through grep
sed -n '/EEE/,/FFF/p' | grep 'C'
I could also do the range and match in a little awk
script (or perl
, python
, etc.). But how would I do this using just one invocation of sed
?
sed pattern-matching
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Consider the simplified file
AAA
BBB
CCC1
DDD
EEE
CCC2
DDD
FFF
GGG
CCC3
HHH
I can pick out the range EEE
to FFF
with
sed -n '/EEE/,/FFF/p'
Suppose though that I want to print any line containing C
but only within the matching range. I can pipe the result from sed
through grep
sed -n '/EEE/,/FFF/p' | grep 'C'
I could also do the range and match in a little awk
script (or perl
, python
, etc.). But how would I do this using just one invocation of sed
?
sed pattern-matching
Consider the simplified file
AAA
BBB
CCC1
DDD
EEE
CCC2
DDD
FFF
GGG
CCC3
HHH
I can pick out the range EEE
to FFF
with
sed -n '/EEE/,/FFF/p'
Suppose though that I want to print any line containing C
but only within the matching range. I can pipe the result from sed
through grep
sed -n '/EEE/,/FFF/p' | grep 'C'
I could also do the range and match in a little awk
script (or perl
, python
, etc.). But how would I do this using just one invocation of sed
?
sed pattern-matching
sed pattern-matching
edited 1 hour ago
choroba
24.9k34168
24.9k34168
asked 1 hour ago


roaima
40.6k547110
40.6k547110
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
Use a block in which you tell sed to only print when it sees C:
sed -n '/EEE/,/FFF//C/p'
add a comment |Â
up vote
2
down vote
You can try :
sed '/EEE/,/FFF/!d;/C/!d'
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Use a block in which you tell sed to only print when it sees C:
sed -n '/EEE/,/FFF//C/p'
add a comment |Â
up vote
5
down vote
Use a block in which you tell sed to only print when it sees C:
sed -n '/EEE/,/FFF//C/p'
add a comment |Â
up vote
5
down vote
up vote
5
down vote
Use a block in which you tell sed to only print when it sees C:
sed -n '/EEE/,/FFF//C/p'
Use a block in which you tell sed to only print when it sees C:
sed -n '/EEE/,/FFF//C/p'
answered 1 hour ago
choroba
24.9k34168
24.9k34168
add a comment |Â
add a comment |Â
up vote
2
down vote
You can try :
sed '/EEE/,/FFF/!d;/C/!d'
add a comment |Â
up vote
2
down vote
You can try :
sed '/EEE/,/FFF/!d;/C/!d'
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You can try :
sed '/EEE/,/FFF/!d;/C/!d'
You can try :
sed '/EEE/,/FFF/!d;/C/!d'
answered 59 mins ago
ctac_
1,111116
1,111116
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%2f472241%2fuse-sed-to-print-selected-lines-within-a-range%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