match space or newline in sed
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I have read and search, but I don't understand what's wrong with it, I want to match: a space, the string 00011, and either a space or a new line.
sed 's:(s)(00011)([sn]):1$033:g'
EDIT: the data looks like this:
ADD 00000 00001 00011
LSH 00011 00100 01111
ADD 00011 10100 00010
JSR 00011101000111010101100010
and $03
is just a string to replace the 00011
I want to end up with something like this:
ADD 00000 00001 $03
LSH $03 00100 01111
ADD $03 10100 00010
JSR 00011101000111010101100010
Thanks
sed regular-expression
add a comment |Â
up vote
3
down vote
favorite
I have read and search, but I don't understand what's wrong with it, I want to match: a space, the string 00011, and either a space or a new line.
sed 's:(s)(00011)([sn]):1$033:g'
EDIT: the data looks like this:
ADD 00000 00001 00011
LSH 00011 00100 01111
ADD 00011 10100 00010
JSR 00011101000111010101100010
and $03
is just a string to replace the 00011
I want to end up with something like this:
ADD 00000 00001 $03
LSH $03 00100 01111
ADD $03 10100 00010
JSR 00011101000111010101100010
Thanks
sed regular-expression
1
What does your input data look like? Note that sincesed
reads newline-delimited data, it will never see the newlines themselves.
– Kusalananda
50 mins ago
What does that$03
stand for? It won't be expanded due to the single quotes, and if it were, it would expand to e.g.bash3
(given your shell isbash
).
– RudiC
44 mins ago
thanks, question edited.
– onlycparra
40 mins ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have read and search, but I don't understand what's wrong with it, I want to match: a space, the string 00011, and either a space or a new line.
sed 's:(s)(00011)([sn]):1$033:g'
EDIT: the data looks like this:
ADD 00000 00001 00011
LSH 00011 00100 01111
ADD 00011 10100 00010
JSR 00011101000111010101100010
and $03
is just a string to replace the 00011
I want to end up with something like this:
ADD 00000 00001 $03
LSH $03 00100 01111
ADD $03 10100 00010
JSR 00011101000111010101100010
Thanks
sed regular-expression
I have read and search, but I don't understand what's wrong with it, I want to match: a space, the string 00011, and either a space or a new line.
sed 's:(s)(00011)([sn]):1$033:g'
EDIT: the data looks like this:
ADD 00000 00001 00011
LSH 00011 00100 01111
ADD 00011 10100 00010
JSR 00011101000111010101100010
and $03
is just a string to replace the 00011
I want to end up with something like this:
ADD 00000 00001 $03
LSH $03 00100 01111
ADD $03 10100 00010
JSR 00011101000111010101100010
Thanks
sed regular-expression
sed regular-expression
edited 30 mins ago
asked 1 hour ago
onlycparra
466
466
1
What does your input data look like? Note that sincesed
reads newline-delimited data, it will never see the newlines themselves.
– Kusalananda
50 mins ago
What does that$03
stand for? It won't be expanded due to the single quotes, and if it were, it would expand to e.g.bash3
(given your shell isbash
).
– RudiC
44 mins ago
thanks, question edited.
– onlycparra
40 mins ago
add a comment |Â
1
What does your input data look like? Note that sincesed
reads newline-delimited data, it will never see the newlines themselves.
– Kusalananda
50 mins ago
What does that$03
stand for? It won't be expanded due to the single quotes, and if it were, it would expand to e.g.bash3
(given your shell isbash
).
– RudiC
44 mins ago
thanks, question edited.
– onlycparra
40 mins ago
1
1
What does your input data look like? Note that since
sed
reads newline-delimited data, it will never see the newlines themselves.– Kusalananda
50 mins ago
What does your input data look like? Note that since
sed
reads newline-delimited data, it will never see the newlines themselves.– Kusalananda
50 mins ago
What does that
$03
stand for? It won't be expanded due to the single quotes, and if it were, it would expand to e.g. bash3
(given your shell is bash
).– RudiC
44 mins ago
What does that
$03
stand for? It won't be expanded due to the single quotes, and if it were, it would expand to e.g. bash3
(given your shell is bash
).– RudiC
44 mins ago
thanks, question edited.
– onlycparra
40 mins ago
thanks, question edited.
– onlycparra
40 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
sed works on a line at a time and it will strip the newlines when processing each line.
So, in order to do what you want, you should match the end of line anchor ($
) rather than a literal newline character.
This should work:
sed 's:(s)(00011)(s|$):1$033:g'
1
I already tried that, but I missed the backslash before the pipe, thanks, it works perfectly.
– onlycparra
18 mins ago
1
This would fail for data such as00011 00011
.
– Kusalananda
7 mins ago
add a comment |Â
up vote
2
down vote
$ sed 's/<00011>/$03/g' file
ADD 00000 00001 $03
LSH $03 00100 01111
ADD $03 10100 00010
JSR 00011101000111010101100010
The <
and >
matches the zero-width word boundaries at the start and end of a word, respectively. BSD sed
would also recognise [[:<:]]
and [[:>:]]
, and GNU sed
also understands b
as a word boundary.
sed
will never see the newlines in the input data. Also, s
is specific to GNU sed
. To match a space character in standard sed
just use a literal space (to match a space-or-tab, use [[:blank:]]
).
1
very complete and informative, thanks
– onlycparra
15 mins ago
add a comment |Â
up vote
0
down vote
This should to the job (a little bit cleaner to read):
sed -r 's/(s)00011(s|$)/1$32/'
or even:
sed -r 's/( )00011( |$)/1$32/'
The output:
ADD 00000 00001 $3
LSH $3 00100 01111
ADD $3 10100 00010
JSR 00011101000111010101100010
This, too, would fail on the data00011 00011
.
– Kusalananda
4 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
sed works on a line at a time and it will strip the newlines when processing each line.
So, in order to do what you want, you should match the end of line anchor ($
) rather than a literal newline character.
This should work:
sed 's:(s)(00011)(s|$):1$033:g'
1
I already tried that, but I missed the backslash before the pipe, thanks, it works perfectly.
– onlycparra
18 mins ago
1
This would fail for data such as00011 00011
.
– Kusalananda
7 mins ago
add a comment |Â
up vote
2
down vote
accepted
sed works on a line at a time and it will strip the newlines when processing each line.
So, in order to do what you want, you should match the end of line anchor ($
) rather than a literal newline character.
This should work:
sed 's:(s)(00011)(s|$):1$033:g'
1
I already tried that, but I missed the backslash before the pipe, thanks, it works perfectly.
– onlycparra
18 mins ago
1
This would fail for data such as00011 00011
.
– Kusalananda
7 mins ago
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
sed works on a line at a time and it will strip the newlines when processing each line.
So, in order to do what you want, you should match the end of line anchor ($
) rather than a literal newline character.
This should work:
sed 's:(s)(00011)(s|$):1$033:g'
sed works on a line at a time and it will strip the newlines when processing each line.
So, in order to do what you want, you should match the end of line anchor ($
) rather than a literal newline character.
This should work:
sed 's:(s)(00011)(s|$):1$033:g'
answered 32 mins ago


Filipe Brandenburger
3,787622
3,787622
1
I already tried that, but I missed the backslash before the pipe, thanks, it works perfectly.
– onlycparra
18 mins ago
1
This would fail for data such as00011 00011
.
– Kusalananda
7 mins ago
add a comment |Â
1
I already tried that, but I missed the backslash before the pipe, thanks, it works perfectly.
– onlycparra
18 mins ago
1
This would fail for data such as00011 00011
.
– Kusalananda
7 mins ago
1
1
I already tried that, but I missed the backslash before the pipe, thanks, it works perfectly.
– onlycparra
18 mins ago
I already tried that, but I missed the backslash before the pipe, thanks, it works perfectly.
– onlycparra
18 mins ago
1
1
This would fail for data such as
00011 00011
.– Kusalananda
7 mins ago
This would fail for data such as
00011 00011
.– Kusalananda
7 mins ago
add a comment |Â
up vote
2
down vote
$ sed 's/<00011>/$03/g' file
ADD 00000 00001 $03
LSH $03 00100 01111
ADD $03 10100 00010
JSR 00011101000111010101100010
The <
and >
matches the zero-width word boundaries at the start and end of a word, respectively. BSD sed
would also recognise [[:<:]]
and [[:>:]]
, and GNU sed
also understands b
as a word boundary.
sed
will never see the newlines in the input data. Also, s
is specific to GNU sed
. To match a space character in standard sed
just use a literal space (to match a space-or-tab, use [[:blank:]]
).
1
very complete and informative, thanks
– onlycparra
15 mins ago
add a comment |Â
up vote
2
down vote
$ sed 's/<00011>/$03/g' file
ADD 00000 00001 $03
LSH $03 00100 01111
ADD $03 10100 00010
JSR 00011101000111010101100010
The <
and >
matches the zero-width word boundaries at the start and end of a word, respectively. BSD sed
would also recognise [[:<:]]
and [[:>:]]
, and GNU sed
also understands b
as a word boundary.
sed
will never see the newlines in the input data. Also, s
is specific to GNU sed
. To match a space character in standard sed
just use a literal space (to match a space-or-tab, use [[:blank:]]
).
1
very complete and informative, thanks
– onlycparra
15 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
$ sed 's/<00011>/$03/g' file
ADD 00000 00001 $03
LSH $03 00100 01111
ADD $03 10100 00010
JSR 00011101000111010101100010
The <
and >
matches the zero-width word boundaries at the start and end of a word, respectively. BSD sed
would also recognise [[:<:]]
and [[:>:]]
, and GNU sed
also understands b
as a word boundary.
sed
will never see the newlines in the input data. Also, s
is specific to GNU sed
. To match a space character in standard sed
just use a literal space (to match a space-or-tab, use [[:blank:]]
).
$ sed 's/<00011>/$03/g' file
ADD 00000 00001 $03
LSH $03 00100 01111
ADD $03 10100 00010
JSR 00011101000111010101100010
The <
and >
matches the zero-width word boundaries at the start and end of a word, respectively. BSD sed
would also recognise [[:<:]]
and [[:>:]]
, and GNU sed
also understands b
as a word boundary.
sed
will never see the newlines in the input data. Also, s
is specific to GNU sed
. To match a space character in standard sed
just use a literal space (to match a space-or-tab, use [[:blank:]]
).
edited 19 mins ago
answered 24 mins ago


Kusalananda
107k14209331
107k14209331
1
very complete and informative, thanks
– onlycparra
15 mins ago
add a comment |Â
1
very complete and informative, thanks
– onlycparra
15 mins ago
1
1
very complete and informative, thanks
– onlycparra
15 mins ago
very complete and informative, thanks
– onlycparra
15 mins ago
add a comment |Â
up vote
0
down vote
This should to the job (a little bit cleaner to read):
sed -r 's/(s)00011(s|$)/1$32/'
or even:
sed -r 's/( )00011( |$)/1$32/'
The output:
ADD 00000 00001 $3
LSH $3 00100 01111
ADD $3 10100 00010
JSR 00011101000111010101100010
This, too, would fail on the data00011 00011
.
– Kusalananda
4 mins ago
add a comment |Â
up vote
0
down vote
This should to the job (a little bit cleaner to read):
sed -r 's/(s)00011(s|$)/1$32/'
or even:
sed -r 's/( )00011( |$)/1$32/'
The output:
ADD 00000 00001 $3
LSH $3 00100 01111
ADD $3 10100 00010
JSR 00011101000111010101100010
This, too, would fail on the data00011 00011
.
– Kusalananda
4 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
This should to the job (a little bit cleaner to read):
sed -r 's/(s)00011(s|$)/1$32/'
or even:
sed -r 's/( )00011( |$)/1$32/'
The output:
ADD 00000 00001 $3
LSH $3 00100 01111
ADD $3 10100 00010
JSR 00011101000111010101100010
This should to the job (a little bit cleaner to read):
sed -r 's/(s)00011(s|$)/1$32/'
or even:
sed -r 's/( )00011( |$)/1$32/'
The output:
ADD 00000 00001 $3
LSH $3 00100 01111
ADD $3 10100 00010
JSR 00011101000111010101100010
answered 29 mins ago


Ravexina
990719
990719
This, too, would fail on the data00011 00011
.
– Kusalananda
4 mins ago
add a comment |Â
This, too, would fail on the data00011 00011
.
– Kusalananda
4 mins ago
This, too, would fail on the data
00011 00011
.– Kusalananda
4 mins ago
This, too, would fail on the data
00011 00011
.– Kusalananda
4 mins ago
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%2f471522%2fmatch-space-or-newline-in-sed%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
1
What does your input data look like? Note that since
sed
reads newline-delimited data, it will never see the newlines themselves.– Kusalananda
50 mins ago
What does that
$03
stand for? It won't be expanded due to the single quotes, and if it were, it would expand to e.g.bash3
(given your shell isbash
).– RudiC
44 mins ago
thanks, question edited.
– onlycparra
40 mins ago