1 not defined in the RE?
My code goes like this:
cat file.ign | sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
Yet I receive an error saying :
sed: 1: "s/^([^A-Za-z0-9]+ )/<ig ...": 1 not defined in the RE
For the life of me, I cannot figure out my misdoing. If you need any extra information for helping me, let me know and I will reply.
sed
New contributor
add a comment |
My code goes like this:
cat file.ign | sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
Yet I receive an error saying :
sed: 1: "s/^([^A-Za-z0-9]+ )/<ig ...": 1 not defined in the RE
For the life of me, I cannot figure out my misdoing. If you need any extra information for helping me, let me know and I will reply.
sed
New contributor
add a comment |
My code goes like this:
cat file.ign | sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
Yet I receive an error saying :
sed: 1: "s/^([^A-Za-z0-9]+ )/<ig ...": 1 not defined in the RE
For the life of me, I cannot figure out my misdoing. If you need any extra information for helping me, let me know and I will reply.
sed
New contributor
My code goes like this:
cat file.ign | sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
Yet I receive an error saying :
sed: 1: "s/^([^A-Za-z0-9]+ )/<ig ...": 1 not defined in the RE
For the life of me, I cannot figure out my misdoing. If you need any extra information for helping me, let me know and I will reply.
sed
sed
New contributor
New contributor
edited 3 hours ago
Jeff Schaller
40.9k1056130
40.9k1056130
New contributor
asked 3 hours ago
Laura Laura
111
111
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as (
and )
Additionally, as noted in a comment by @BenjaminW, +
is also literal in BRE. GNU sed supports +
as a quantifier in BRE:
sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
(but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E
or -r
command line switch as appropriate (check your version's documentation):
sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
or use the POSIX-compliant quantifier {1,}
sed 's/^([^A-Za-z0-9]{1,} )/<ignore>1</ignore>/g'
ASIDE the g
(global replacement) modifier won't have any effect here, since ^
anchors the expression to the start of the pattern (which can occur only once per line)
1
Furthermore,+
is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.
– Benjamin W.
2 hours ago
@BenjaminW. oops yes that's a good point - I missed that
– steeldriver
2 hours ago
The-E
also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.
– Thomas Dickey
1 hour ago
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
});
}
});
Laura is a new contributor. Be nice, and check out our Code of Conduct.
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%2f499185%2f1-not-defined-in-the-re%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as (
and )
Additionally, as noted in a comment by @BenjaminW, +
is also literal in BRE. GNU sed supports +
as a quantifier in BRE:
sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
(but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E
or -r
command line switch as appropriate (check your version's documentation):
sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
or use the POSIX-compliant quantifier {1,}
sed 's/^([^A-Za-z0-9]{1,} )/<ignore>1</ignore>/g'
ASIDE the g
(global replacement) modifier won't have any effect here, since ^
anchors the expression to the start of the pattern (which can occur only once per line)
1
Furthermore,+
is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.
– Benjamin W.
2 hours ago
@BenjaminW. oops yes that's a good point - I missed that
– steeldriver
2 hours ago
The-E
also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.
– Thomas Dickey
1 hour ago
add a comment |
Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as (
and )
Additionally, as noted in a comment by @BenjaminW, +
is also literal in BRE. GNU sed supports +
as a quantifier in BRE:
sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
(but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E
or -r
command line switch as appropriate (check your version's documentation):
sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
or use the POSIX-compliant quantifier {1,}
sed 's/^([^A-Za-z0-9]{1,} )/<ignore>1</ignore>/g'
ASIDE the g
(global replacement) modifier won't have any effect here, since ^
anchors the expression to the start of the pattern (which can occur only once per line)
1
Furthermore,+
is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.
– Benjamin W.
2 hours ago
@BenjaminW. oops yes that's a good point - I missed that
– steeldriver
2 hours ago
The-E
also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.
– Thomas Dickey
1 hour ago
add a comment |
Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as (
and )
Additionally, as noted in a comment by @BenjaminW, +
is also literal in BRE. GNU sed supports +
as a quantifier in BRE:
sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
(but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E
or -r
command line switch as appropriate (check your version's documentation):
sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
or use the POSIX-compliant quantifier {1,}
sed 's/^([^A-Za-z0-9]{1,} )/<ignore>1</ignore>/g'
ASIDE the g
(global replacement) modifier won't have any effect here, since ^
anchors the expression to the start of the pattern (which can occur only once per line)
Parentheses are literal in basic regular expression (BRE) syntax - to make them denote a capture group, they must be escaped, as (
and )
Additionally, as noted in a comment by @BenjaminW, +
is also literal in BRE. GNU sed supports +
as a quantifier in BRE:
sed 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
(but other implementations might not). Alternatively, turn on extended regular expression (ERE) mode using the -E
or -r
command line switch as appropriate (check your version's documentation):
sed -E 's/^([^A-Za-z0-9]+ )/<ignore>1</ignore>/g'
or use the POSIX-compliant quantifier {1,}
sed 's/^([^A-Za-z0-9]{1,} )/<ignore>1</ignore>/g'
ASIDE the g
(global replacement) modifier won't have any effect here, since ^
anchors the expression to the start of the pattern (which can occur only once per line)
edited 59 mins ago
answered 3 hours ago
steeldriversteeldriver
36k35286
36k35286
1
Furthermore,+
is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.
– Benjamin W.
2 hours ago
@BenjaminW. oops yes that's a good point - I missed that
– steeldriver
2 hours ago
The-E
also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.
– Thomas Dickey
1 hour ago
add a comment |
1
Furthermore,+
is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.
– Benjamin W.
2 hours ago
@BenjaminW. oops yes that's a good point - I missed that
– steeldriver
2 hours ago
The-E
also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.
– Thomas Dickey
1 hour ago
1
1
Furthermore,
+
is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.– Benjamin W.
2 hours ago
Furthermore,
+
is only avalable in ERE; GNU sed supports it as an extension in BRE, but is has to be escaped.– Benjamin W.
2 hours ago
@BenjaminW. oops yes that's a good point - I missed that
– steeldriver
2 hours ago
@BenjaminW. oops yes that's a good point - I missed that
– steeldriver
2 hours ago
The
-E
also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.– Thomas Dickey
1 hour ago
The
-E
also is GNU or FreeBSD sed, not in POSIX. If you're going to recommend a non-POSIX solution, mentioning that might help the reader.– Thomas Dickey
1 hour ago
add a comment |
Laura is a new contributor. Be nice, and check out our Code of Conduct.
Laura is a new contributor. Be nice, and check out our Code of Conduct.
Laura is a new contributor. Be nice, and check out our Code of Conduct.
Laura is a new contributor. Be nice, and check out our Code of Conduct.
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%2f499185%2f1-not-defined-in-the-re%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