Sed doesn't work as expected
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I understand sed
will
- Applies all instructions on line 1, then line 2...
- Previous instructions may change the pattern space so the next instruction will operate on that modified pattern space (instead of the original text)
The example is:
sample.txt file
pig cow
Command
sed -e 's/pig/cow/; s/cow/horse/;' sample.txt
Expected Output
horse horse
Real Output
horse cow
The reason for my expected output is:
- First instruction substituted pig with cow in the pattern space
- Second instruction substituted 2 pigs with 2 horses in the pattern space
sed
add a comment |Â
up vote
0
down vote
favorite
I understand sed
will
- Applies all instructions on line 1, then line 2...
- Previous instructions may change the pattern space so the next instruction will operate on that modified pattern space (instead of the original text)
The example is:
sample.txt file
pig cow
Command
sed -e 's/pig/cow/; s/cow/horse/;' sample.txt
Expected Output
horse horse
Real Output
horse cow
The reason for my expected output is:
- First instruction substituted pig with cow in the pattern space
- Second instruction substituted 2 pigs with 2 horses in the pattern space
sed
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I understand sed
will
- Applies all instructions on line 1, then line 2...
- Previous instructions may change the pattern space so the next instruction will operate on that modified pattern space (instead of the original text)
The example is:
sample.txt file
pig cow
Command
sed -e 's/pig/cow/; s/cow/horse/;' sample.txt
Expected Output
horse horse
Real Output
horse cow
The reason for my expected output is:
- First instruction substituted pig with cow in the pattern space
- Second instruction substituted 2 pigs with 2 horses in the pattern space
sed
I understand sed
will
- Applies all instructions on line 1, then line 2...
- Previous instructions may change the pattern space so the next instruction will operate on that modified pattern space (instead of the original text)
The example is:
sample.txt file
pig cow
Command
sed -e 's/pig/cow/; s/cow/horse/;' sample.txt
Expected Output
horse horse
Real Output
horse cow
The reason for my expected output is:
- First instruction substituted pig with cow in the pattern space
- Second instruction substituted 2 pigs with 2 horses in the pattern space
sed
sed
asked 3 mins ago
Tran Triet
808
808
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f474407%2fsed-doesnt-work-as-expected%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