What is the purpose of -e in sed command?-e option in sedsed on OSX insert at a certain lineReplace matches...
File globbing pattern, !(*example), behaves differently in bash script than it does in bash shell
Why do Russians call their women expensive ("дорогая")?
What caused the tendency for conservatives to not support climate change reform?
Employer demanding to see degree after poor code review
Why colon to denote that a value belongs to a type?
Were pen cap holes designed to prevent death by suffocation if swallowed?
Can a non-EU citizen travel within schengen zone freely without passport?
What is the difference between nullifying your vote and not going to vote at all?
Can a wire having a 610-670 THz (frequency of blue light) AC frequency supply, generate blue light?
If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?
How do you deal with an abrupt change in personality for a protagonist?
Yandex Programming Contest: Alarms
Apparent Ring of Craters on the Moon
Leading and Suffering Numbers
Do you play the upbeat when beginning to play a series of notes, and then after?
Why does the 6502 have the BIT instruction?
Could I be denied entry into Ireland due to medical and police situations during a previous UK visit?
1960s sci-fi novella with a character who is treated as invisible by being ignored
What does uniform continuity mean exactly?
Restoring order in a deck of playing cards
How to capture more stars?
Is there an explanation for Austria's Freedom Party virtually retaining its vote share despite recent scandal?
What is the best linguistic term for describing the kw > p / gw > b change, and its usual companion s > h
Smart people send dumb people to a new planet on a space craft that crashes into a body of water
What is the purpose of -e in sed command?
-e option in sedsed on OSX insert at a certain lineReplace matches with multiline string using sedIs it normal to use the grave (`) symbol, followed by an apostraphe (') to quote?How to switch the first letters of two words?Is it possible to pass arguments to a sed script?What was the first Unix platform to have the 'yes' command?Are there standard versions of `sed` on which `-E` is unsupported?( sed command)-> sed $fooUse sed to find and replace a string in multiple filesRunning several sed commands on same files simultaneouslySed to replace lowercase and capital strings
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I can't find any documentation about the sed
-e
switch, for simple replace, do I need it?
e.g.
sed 's/foo/bar/'
VS
sed -e 's/foo/bar/'
linux shell text sed command
migrated from stackoverflow.com Mar 1 '12 at 17:30
This question came from our site for professional and enthusiast programmers.
add a comment |
I can't find any documentation about the sed
-e
switch, for simple replace, do I need it?
e.g.
sed 's/foo/bar/'
VS
sed -e 's/foo/bar/'
linux shell text sed command
migrated from stackoverflow.com Mar 1 '12 at 17:30
This question came from our site for professional and enthusiast programmers.
13
Are you sure you didn't find this inman sed
?
– BoltClock
Mar 1 '12 at 8:32
4
You don't find potongs explanation, why not to use "cmd1;cmd2"
– user unknown
Mar 1 '12 at 22:51
add a comment |
I can't find any documentation about the sed
-e
switch, for simple replace, do I need it?
e.g.
sed 's/foo/bar/'
VS
sed -e 's/foo/bar/'
linux shell text sed command
I can't find any documentation about the sed
-e
switch, for simple replace, do I need it?
e.g.
sed 's/foo/bar/'
VS
sed -e 's/foo/bar/'
linux shell text sed command
linux shell text sed command
asked Mar 1 '12 at 8:31
HowardHoward
297145
297145
migrated from stackoverflow.com Mar 1 '12 at 17:30
This question came from our site for professional and enthusiast programmers.
migrated from stackoverflow.com Mar 1 '12 at 17:30
This question came from our site for professional and enthusiast programmers.
13
Are you sure you didn't find this inman sed
?
– BoltClock
Mar 1 '12 at 8:32
4
You don't find potongs explanation, why not to use "cmd1;cmd2"
– user unknown
Mar 1 '12 at 22:51
add a comment |
13
Are you sure you didn't find this inman sed
?
– BoltClock
Mar 1 '12 at 8:32
4
You don't find potongs explanation, why not to use "cmd1;cmd2"
– user unknown
Mar 1 '12 at 22:51
13
13
Are you sure you didn't find this in
man sed
?– BoltClock
Mar 1 '12 at 8:32
Are you sure you didn't find this in
man sed
?– BoltClock
Mar 1 '12 at 8:32
4
4
You don't find potongs explanation, why not to use "cmd1;cmd2"
– user unknown
Mar 1 '12 at 22:51
You don't find potongs explanation, why not to use "cmd1;cmd2"
– user unknown
Mar 1 '12 at 22:51
add a comment |
3 Answers
3
active
oldest
votes
This might work for you:
sed -e '/foo/i' -e 'bar' -e '/fred/a' -e 'barny' -e '/harry/c' -e 'potter' file
In each case the i
(insert),a
(append) and c
(change) commands need to be terminated by a newline.
Normally commands can be separated by a ;
e.g. /foo/d;/bar/d
and grouped by {...
} e.g. /foo/{h;d}
but for the i,a,c
commands the -e
provides a way of separating the commands.
The alternative is to use the shell(bash) to insert a newline:
sed '/foo/ibar'$'n''/fred/abarney'$'n''/harry/cpotter' file
1
On at least some sed implementations (for instance, on FreeBSD), you also need to end labels and branch commands using newlines/-e
, rather than with semicolons. This won't work:sed ':a; /x/ { s/x/y/g; ba }; q' <<< "jxm"
. But this will:sed -e ':a' -e '/x/ { s/x/y/g; ba' -e '}; q' <<< "jxm"
– dubiousjim
Oct 16 '12 at 7:35
I'm not sure how necessary is themust be terminated with a newline
phrase means here. When I tested here in mycygwin
, this works:sed '/foo/ibar' file
. So now that we can fuse together the separate expressions into one, this raises again to the original question: What is the true purpose of the-e
?
– typelogic
Oct 22 '18 at 17:11
add a comment |
From the man page:
-e script, --expression=script
add the script to the commands to be executed
So you can use multiple -e
options to build up a script out of many parts.
$ sed -e "s/foo/bar/" -e "/FOO/d"
Would first replace foo
with bar
and then delete every line containing FOO
.
1
So, you don't need '-e' if you only have one script, right?
– JohnyTex
Aug 8 '17 at 10:26
I, too, am searching for the true purpose of-e
– typelogic
Oct 22 '18 at 17:14
add a comment |
-e
, equivalent to --expression
, is optional, unless you are stringing several expressions together (not common) as shown in another Answer.
Aside: ;
can be used instead in the same expression to execute several expressions one after the other.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f33157%2fwhat-is-the-purpose-of-e-in-sed-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This might work for you:
sed -e '/foo/i' -e 'bar' -e '/fred/a' -e 'barny' -e '/harry/c' -e 'potter' file
In each case the i
(insert),a
(append) and c
(change) commands need to be terminated by a newline.
Normally commands can be separated by a ;
e.g. /foo/d;/bar/d
and grouped by {...
} e.g. /foo/{h;d}
but for the i,a,c
commands the -e
provides a way of separating the commands.
The alternative is to use the shell(bash) to insert a newline:
sed '/foo/ibar'$'n''/fred/abarney'$'n''/harry/cpotter' file
1
On at least some sed implementations (for instance, on FreeBSD), you also need to end labels and branch commands using newlines/-e
, rather than with semicolons. This won't work:sed ':a; /x/ { s/x/y/g; ba }; q' <<< "jxm"
. But this will:sed -e ':a' -e '/x/ { s/x/y/g; ba' -e '}; q' <<< "jxm"
– dubiousjim
Oct 16 '12 at 7:35
I'm not sure how necessary is themust be terminated with a newline
phrase means here. When I tested here in mycygwin
, this works:sed '/foo/ibar' file
. So now that we can fuse together the separate expressions into one, this raises again to the original question: What is the true purpose of the-e
?
– typelogic
Oct 22 '18 at 17:11
add a comment |
This might work for you:
sed -e '/foo/i' -e 'bar' -e '/fred/a' -e 'barny' -e '/harry/c' -e 'potter' file
In each case the i
(insert),a
(append) and c
(change) commands need to be terminated by a newline.
Normally commands can be separated by a ;
e.g. /foo/d;/bar/d
and grouped by {...
} e.g. /foo/{h;d}
but for the i,a,c
commands the -e
provides a way of separating the commands.
The alternative is to use the shell(bash) to insert a newline:
sed '/foo/ibar'$'n''/fred/abarney'$'n''/harry/cpotter' file
1
On at least some sed implementations (for instance, on FreeBSD), you also need to end labels and branch commands using newlines/-e
, rather than with semicolons. This won't work:sed ':a; /x/ { s/x/y/g; ba }; q' <<< "jxm"
. But this will:sed -e ':a' -e '/x/ { s/x/y/g; ba' -e '}; q' <<< "jxm"
– dubiousjim
Oct 16 '12 at 7:35
I'm not sure how necessary is themust be terminated with a newline
phrase means here. When I tested here in mycygwin
, this works:sed '/foo/ibar' file
. So now that we can fuse together the separate expressions into one, this raises again to the original question: What is the true purpose of the-e
?
– typelogic
Oct 22 '18 at 17:11
add a comment |
This might work for you:
sed -e '/foo/i' -e 'bar' -e '/fred/a' -e 'barny' -e '/harry/c' -e 'potter' file
In each case the i
(insert),a
(append) and c
(change) commands need to be terminated by a newline.
Normally commands can be separated by a ;
e.g. /foo/d;/bar/d
and grouped by {...
} e.g. /foo/{h;d}
but for the i,a,c
commands the -e
provides a way of separating the commands.
The alternative is to use the shell(bash) to insert a newline:
sed '/foo/ibar'$'n''/fred/abarney'$'n''/harry/cpotter' file
This might work for you:
sed -e '/foo/i' -e 'bar' -e '/fred/a' -e 'barny' -e '/harry/c' -e 'potter' file
In each case the i
(insert),a
(append) and c
(change) commands need to be terminated by a newline.
Normally commands can be separated by a ;
e.g. /foo/d;/bar/d
and grouped by {...
} e.g. /foo/{h;d}
but for the i,a,c
commands the -e
provides a way of separating the commands.
The alternative is to use the shell(bash) to insert a newline:
sed '/foo/ibar'$'n''/fred/abarney'$'n''/harry/cpotter' file
edited Jun 3 '15 at 6:30
lcd047
5,9561432
5,9561432
answered Mar 1 '12 at 9:16
potong
1
On at least some sed implementations (for instance, on FreeBSD), you also need to end labels and branch commands using newlines/-e
, rather than with semicolons. This won't work:sed ':a; /x/ { s/x/y/g; ba }; q' <<< "jxm"
. But this will:sed -e ':a' -e '/x/ { s/x/y/g; ba' -e '}; q' <<< "jxm"
– dubiousjim
Oct 16 '12 at 7:35
I'm not sure how necessary is themust be terminated with a newline
phrase means here. When I tested here in mycygwin
, this works:sed '/foo/ibar' file
. So now that we can fuse together the separate expressions into one, this raises again to the original question: What is the true purpose of the-e
?
– typelogic
Oct 22 '18 at 17:11
add a comment |
1
On at least some sed implementations (for instance, on FreeBSD), you also need to end labels and branch commands using newlines/-e
, rather than with semicolons. This won't work:sed ':a; /x/ { s/x/y/g; ba }; q' <<< "jxm"
. But this will:sed -e ':a' -e '/x/ { s/x/y/g; ba' -e '}; q' <<< "jxm"
– dubiousjim
Oct 16 '12 at 7:35
I'm not sure how necessary is themust be terminated with a newline
phrase means here. When I tested here in mycygwin
, this works:sed '/foo/ibar' file
. So now that we can fuse together the separate expressions into one, this raises again to the original question: What is the true purpose of the-e
?
– typelogic
Oct 22 '18 at 17:11
1
1
On at least some sed implementations (for instance, on FreeBSD), you also need to end labels and branch commands using newlines/
-e
, rather than with semicolons. This won't work: sed ':a; /x/ { s/x/y/g; ba }; q' <<< "jxm"
. But this will: sed -e ':a' -e '/x/ { s/x/y/g; ba' -e '}; q' <<< "jxm"
– dubiousjim
Oct 16 '12 at 7:35
On at least some sed implementations (for instance, on FreeBSD), you also need to end labels and branch commands using newlines/
-e
, rather than with semicolons. This won't work: sed ':a; /x/ { s/x/y/g; ba }; q' <<< "jxm"
. But this will: sed -e ':a' -e '/x/ { s/x/y/g; ba' -e '}; q' <<< "jxm"
– dubiousjim
Oct 16 '12 at 7:35
I'm not sure how necessary is the
must be terminated with a newline
phrase means here. When I tested here in my cygwin
, this works: sed '/foo/ibar' file
. So now that we can fuse together the separate expressions into one, this raises again to the original question: What is the true purpose of the -e
?– typelogic
Oct 22 '18 at 17:11
I'm not sure how necessary is the
must be terminated with a newline
phrase means here. When I tested here in my cygwin
, this works: sed '/foo/ibar' file
. So now that we can fuse together the separate expressions into one, this raises again to the original question: What is the true purpose of the -e
?– typelogic
Oct 22 '18 at 17:11
add a comment |
From the man page:
-e script, --expression=script
add the script to the commands to be executed
So you can use multiple -e
options to build up a script out of many parts.
$ sed -e "s/foo/bar/" -e "/FOO/d"
Would first replace foo
with bar
and then delete every line containing FOO
.
1
So, you don't need '-e' if you only have one script, right?
– JohnyTex
Aug 8 '17 at 10:26
I, too, am searching for the true purpose of-e
– typelogic
Oct 22 '18 at 17:14
add a comment |
From the man page:
-e script, --expression=script
add the script to the commands to be executed
So you can use multiple -e
options to build up a script out of many parts.
$ sed -e "s/foo/bar/" -e "/FOO/d"
Would first replace foo
with bar
and then delete every line containing FOO
.
1
So, you don't need '-e' if you only have one script, right?
– JohnyTex
Aug 8 '17 at 10:26
I, too, am searching for the true purpose of-e
– typelogic
Oct 22 '18 at 17:14
add a comment |
From the man page:
-e script, --expression=script
add the script to the commands to be executed
So you can use multiple -e
options to build up a script out of many parts.
$ sed -e "s/foo/bar/" -e "/FOO/d"
Would first replace foo
with bar
and then delete every line containing FOO
.
From the man page:
-e script, --expression=script
add the script to the commands to be executed
So you can use multiple -e
options to build up a script out of many parts.
$ sed -e "s/foo/bar/" -e "/FOO/d"
Would first replace foo
with bar
and then delete every line containing FOO
.
answered Mar 1 '12 at 8:33
user16144
1
So, you don't need '-e' if you only have one script, right?
– JohnyTex
Aug 8 '17 at 10:26
I, too, am searching for the true purpose of-e
– typelogic
Oct 22 '18 at 17:14
add a comment |
1
So, you don't need '-e' if you only have one script, right?
– JohnyTex
Aug 8 '17 at 10:26
I, too, am searching for the true purpose of-e
– typelogic
Oct 22 '18 at 17:14
1
1
So, you don't need '-e' if you only have one script, right?
– JohnyTex
Aug 8 '17 at 10:26
So, you don't need '-e' if you only have one script, right?
– JohnyTex
Aug 8 '17 at 10:26
I, too, am searching for the true purpose of
-e
– typelogic
Oct 22 '18 at 17:14
I, too, am searching for the true purpose of
-e
– typelogic
Oct 22 '18 at 17:14
add a comment |
-e
, equivalent to --expression
, is optional, unless you are stringing several expressions together (not common) as shown in another Answer.
Aside: ;
can be used instead in the same expression to execute several expressions one after the other.
add a comment |
-e
, equivalent to --expression
, is optional, unless you are stringing several expressions together (not common) as shown in another Answer.
Aside: ;
can be used instead in the same expression to execute several expressions one after the other.
add a comment |
-e
, equivalent to --expression
, is optional, unless you are stringing several expressions together (not common) as shown in another Answer.
Aside: ;
can be used instead in the same expression to execute several expressions one after the other.
-e
, equivalent to --expression
, is optional, unless you are stringing several expressions together (not common) as shown in another Answer.
Aside: ;
can be used instead in the same expression to execute several expressions one after the other.
answered 25 mins ago
flow2kflow2k
212213
212213
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f33157%2fwhat-is-the-purpose-of-e-in-sed-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
13
Are you sure you didn't find this in
man sed
?– BoltClock
Mar 1 '12 at 8:32
4
You don't find potongs explanation, why not to use "cmd1;cmd2"
– user unknown
Mar 1 '12 at 22:51