sed 's/-([0-9.]+)/(1)/g' inputfile what does this command mean?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I am trying to find out what the following command means:
sed 's/-([0-9.]+)/(1)/g' inputfile
I know it has to do with non-digit characters.
sed
New contributor
add a comment |Â
up vote
2
down vote
favorite
I am trying to find out what the following command means:
sed 's/-([0-9.]+)/(1)/g' inputfile
I know it has to do with non-digit characters.
sed
New contributor
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am trying to find out what the following command means:
sed 's/-([0-9.]+)/(1)/g' inputfile
I know it has to do with non-digit characters.
sed
New contributor
I am trying to find out what the following command means:
sed 's/-([0-9.]+)/(1)/g' inputfile
I know it has to do with non-digit characters.
sed
sed
New contributor
New contributor
edited 18 mins ago
ilkkachu
51.5k678142
51.5k678142
New contributor
asked 27 mins ago
Quincy Darko
211
211
New contributor
New contributor
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45
into (123.45)
.
In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+
into (1+)
, but leaves stuff like -123
as-is.
Taken apart, in the left-hand pattern, the dash matches itself, [0-9.]
matches any one digit or dot, and the ( )
capture the part in between. In the replacement, the parenthesis are literal, and 1
puts back whatever was within the ( )
.
In extended regular expressions, a +
means "one or more of the previous", so [0-9.]+
would mean "one or more digits or dots". In a standard regex, neither +
or +
has any special meaning, however, but GNU systems are a bit lax on that, and +
takes the "one or more" sense there.
Portably, that should be either
sed -E 's/-([0-9.]+)/(1)/'
or
sed 's/-([0-9.]1,)/(1)/'
Both of which will replace a dash in front of a number with parenthesis around it.
add a comment |Â
up vote
1
down vote
Looks like it changing the format of negative numbers from having a -
in front of them to instead being surrounded by parentheses.
It searches for a sequence that starts with -
followed by a sequence of numerals and decimals [0-9.]
being a match to numerals and decimals, and +
modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...)
, which is the first expression, and in the replacement clause, (1)
will paste the first expression between ()
. End result is removal of a negative sign in front of a number and wrapping it in parentheses.
So with an input of:
test value: -123.4
the output should be of the form
test value: (123.4)
2
...and adds parentheses around the result, too. Just changing the display style.
â drewbenn
13 mins ago
1
Ah, yes, I did miss that. I'll edit it in.
â Christian Gibbons
12 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45
into (123.45)
.
In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+
into (1+)
, but leaves stuff like -123
as-is.
Taken apart, in the left-hand pattern, the dash matches itself, [0-9.]
matches any one digit or dot, and the ( )
capture the part in between. In the replacement, the parenthesis are literal, and 1
puts back whatever was within the ( )
.
In extended regular expressions, a +
means "one or more of the previous", so [0-9.]+
would mean "one or more digits or dots". In a standard regex, neither +
or +
has any special meaning, however, but GNU systems are a bit lax on that, and +
takes the "one or more" sense there.
Portably, that should be either
sed -E 's/-([0-9.]+)/(1)/'
or
sed 's/-([0-9.]1,)/(1)/'
Both of which will replace a dash in front of a number with parenthesis around it.
add a comment |Â
up vote
2
down vote
In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45
into (123.45)
.
In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+
into (1+)
, but leaves stuff like -123
as-is.
Taken apart, in the left-hand pattern, the dash matches itself, [0-9.]
matches any one digit or dot, and the ( )
capture the part in between. In the replacement, the parenthesis are literal, and 1
puts back whatever was within the ( )
.
In extended regular expressions, a +
means "one or more of the previous", so [0-9.]+
would mean "one or more digits or dots". In a standard regex, neither +
or +
has any special meaning, however, but GNU systems are a bit lax on that, and +
takes the "one or more" sense there.
Portably, that should be either
sed -E 's/-([0-9.]+)/(1)/'
or
sed 's/-([0-9.]1,)/(1)/'
Both of which will replace a dash in front of a number with parenthesis around it.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45
into (123.45)
.
In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+
into (1+)
, but leaves stuff like -123
as-is.
Taken apart, in the left-hand pattern, the dash matches itself, [0-9.]
matches any one digit or dot, and the ( )
capture the part in between. In the replacement, the parenthesis are literal, and 1
puts back whatever was within the ( )
.
In extended regular expressions, a +
means "one or more of the previous", so [0-9.]+
would mean "one or more digits or dots". In a standard regex, neither +
or +
has any special meaning, however, but GNU systems are a bit lax on that, and +
takes the "one or more" sense there.
Portably, that should be either
sed -E 's/-([0-9.]+)/(1)/'
or
sed 's/-([0-9.]1,)/(1)/'
Both of which will replace a dash in front of a number with parenthesis around it.
In GNU sed, it looks for a dash followed by some digits or dots, and replaces that with the same digits in parenthesis. That is, it turns -123.45
into (123.45)
.
In standard sed, it looks for a dash, a digit or dot, and a plus sign, and then removes the dash and surrounds the rest in parenthesis. That is, it turns -1+
into (1+)
, but leaves stuff like -123
as-is.
Taken apart, in the left-hand pattern, the dash matches itself, [0-9.]
matches any one digit or dot, and the ( )
capture the part in between. In the replacement, the parenthesis are literal, and 1
puts back whatever was within the ( )
.
In extended regular expressions, a +
means "one or more of the previous", so [0-9.]+
would mean "one or more digits or dots". In a standard regex, neither +
or +
has any special meaning, however, but GNU systems are a bit lax on that, and +
takes the "one or more" sense there.
Portably, that should be either
sed -E 's/-([0-9.]+)/(1)/'
or
sed 's/-([0-9.]1,)/(1)/'
Both of which will replace a dash in front of a number with parenthesis around it.
edited 4 mins ago
answered 10 mins ago
ilkkachu
51.5k678142
51.5k678142
add a comment |Â
add a comment |Â
up vote
1
down vote
Looks like it changing the format of negative numbers from having a -
in front of them to instead being surrounded by parentheses.
It searches for a sequence that starts with -
followed by a sequence of numerals and decimals [0-9.]
being a match to numerals and decimals, and +
modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...)
, which is the first expression, and in the replacement clause, (1)
will paste the first expression between ()
. End result is removal of a negative sign in front of a number and wrapping it in parentheses.
So with an input of:
test value: -123.4
the output should be of the form
test value: (123.4)
2
...and adds parentheses around the result, too. Just changing the display style.
â drewbenn
13 mins ago
1
Ah, yes, I did miss that. I'll edit it in.
â Christian Gibbons
12 mins ago
add a comment |Â
up vote
1
down vote
Looks like it changing the format of negative numbers from having a -
in front of them to instead being surrounded by parentheses.
It searches for a sequence that starts with -
followed by a sequence of numerals and decimals [0-9.]
being a match to numerals and decimals, and +
modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...)
, which is the first expression, and in the replacement clause, (1)
will paste the first expression between ()
. End result is removal of a negative sign in front of a number and wrapping it in parentheses.
So with an input of:
test value: -123.4
the output should be of the form
test value: (123.4)
2
...and adds parentheses around the result, too. Just changing the display style.
â drewbenn
13 mins ago
1
Ah, yes, I did miss that. I'll edit it in.
â Christian Gibbons
12 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Looks like it changing the format of negative numbers from having a -
in front of them to instead being surrounded by parentheses.
It searches for a sequence that starts with -
followed by a sequence of numerals and decimals [0-9.]
being a match to numerals and decimals, and +
modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...)
, which is the first expression, and in the replacement clause, (1)
will paste the first expression between ()
. End result is removal of a negative sign in front of a number and wrapping it in parentheses.
So with an input of:
test value: -123.4
the output should be of the form
test value: (123.4)
Looks like it changing the format of negative numbers from having a -
in front of them to instead being surrounded by parentheses.
It searches for a sequence that starts with -
followed by a sequence of numerals and decimals [0-9.]
being a match to numerals and decimals, and +
modifying it to match one or more such character in a sequence. The sequence of numerals and decimals are inside (...)
, which is the first expression, and in the replacement clause, (1)
will paste the first expression between ()
. End result is removal of a negative sign in front of a number and wrapping it in parentheses.
So with an input of:
test value: -123.4
the output should be of the form
test value: (123.4)
edited 9 mins ago
answered 22 mins ago
Christian Gibbons
261110
261110
2
...and adds parentheses around the result, too. Just changing the display style.
â drewbenn
13 mins ago
1
Ah, yes, I did miss that. I'll edit it in.
â Christian Gibbons
12 mins ago
add a comment |Â
2
...and adds parentheses around the result, too. Just changing the display style.
â drewbenn
13 mins ago
1
Ah, yes, I did miss that. I'll edit it in.
â Christian Gibbons
12 mins ago
2
2
...and adds parentheses around the result, too. Just changing the display style.
â drewbenn
13 mins ago
...and adds parentheses around the result, too. Just changing the display style.
â drewbenn
13 mins ago
1
1
Ah, yes, I did miss that. I'll edit it in.
â Christian Gibbons
12 mins ago
Ah, yes, I did miss that. I'll edit it in.
â Christian Gibbons
12 mins ago
add a comment |Â
Quincy Darko is a new contributor. Be nice, and check out our Code of Conduct.
Quincy Darko is a new contributor. Be nice, and check out our Code of Conduct.
Quincy Darko is a new contributor. Be nice, and check out our Code of Conduct.
Quincy Darko 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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471397%2fsed-s-0-9-1-g-inputfile-what-does-this-command-mean%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