sed command that replaces number and word by two
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
1) sed command which puts two of the first 'w' on each line. E.g "hewor" = "hewwor".
and
2) sed command which puts two of the first digit on each line E.g "hew0r" = "hew00r"
For first one I got
$ sed s/w/ww/
for the second one I don't understand how to replicate the same digit for example I got
$ sed s/[0-9]/00/
would work but it would have to be zero each time. How do I get the same digit?
sed
 |Â
show 3 more comments
up vote
1
down vote
favorite
1) sed command which puts two of the first 'w' on each line. E.g "hewor" = "hewwor".
and
2) sed command which puts two of the first digit on each line E.g "hew0r" = "hew00r"
For first one I got
$ sed s/w/ww/
for the second one I don't understand how to replicate the same digit for example I got
$ sed s/[0-9]/00/
would work but it would have to be zero each time. How do I get the same digit?
sed
1
How about reading the manual... You'll learn how to reference the matched portion, regardless of what's in the LHS. ;)
â don_crissti
Jan 22 at 0:13
My bad, I meant $sed s/[0-9]/00/ as you can see, it has to be zero. I'm looking for a way for the digit to be the one found in the [0-9].
â Tinler
Jan 22 at 0:20
"sed s/[0-9]//" does the exact same as "sed s/[0-9]/00/" or am I missing something?
â Tinler
Jan 22 at 0:42
Yes. It becomes hew4r -> hew00r. I want hew44r. Also, why should I use that instead of "sed s/[0-9]/00/"? For this and the first example?
â Tinler
Jan 22 at 0:51
OK. in gnu sed usingrefers to the previously matched regex. In bsd sed this is done using
&
. So in your case sincedoes not work, you can use
sed 's/[0-9]/&&/'
. Actuall using&
will work even in gnu sed.
â George Vasiliou
Jan 22 at 1:02
 |Â
show 3 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
1) sed command which puts two of the first 'w' on each line. E.g "hewor" = "hewwor".
and
2) sed command which puts two of the first digit on each line E.g "hew0r" = "hew00r"
For first one I got
$ sed s/w/ww/
for the second one I don't understand how to replicate the same digit for example I got
$ sed s/[0-9]/00/
would work but it would have to be zero each time. How do I get the same digit?
sed
1) sed command which puts two of the first 'w' on each line. E.g "hewor" = "hewwor".
and
2) sed command which puts two of the first digit on each line E.g "hew0r" = "hew00r"
For first one I got
$ sed s/w/ww/
for the second one I don't understand how to replicate the same digit for example I got
$ sed s/[0-9]/00/
would work but it would have to be zero each time. How do I get the same digit?
sed
edited Jan 22 at 0:20
asked Jan 22 at 0:08
Tinler
1295
1295
1
How about reading the manual... You'll learn how to reference the matched portion, regardless of what's in the LHS. ;)
â don_crissti
Jan 22 at 0:13
My bad, I meant $sed s/[0-9]/00/ as you can see, it has to be zero. I'm looking for a way for the digit to be the one found in the [0-9].
â Tinler
Jan 22 at 0:20
"sed s/[0-9]//" does the exact same as "sed s/[0-9]/00/" or am I missing something?
â Tinler
Jan 22 at 0:42
Yes. It becomes hew4r -> hew00r. I want hew44r. Also, why should I use that instead of "sed s/[0-9]/00/"? For this and the first example?
â Tinler
Jan 22 at 0:51
OK. in gnu sed usingrefers to the previously matched regex. In bsd sed this is done using
&
. So in your case sincedoes not work, you can use
sed 's/[0-9]/&&/'
. Actuall using&
will work even in gnu sed.
â George Vasiliou
Jan 22 at 1:02
 |Â
show 3 more comments
1
How about reading the manual... You'll learn how to reference the matched portion, regardless of what's in the LHS. ;)
â don_crissti
Jan 22 at 0:13
My bad, I meant $sed s/[0-9]/00/ as you can see, it has to be zero. I'm looking for a way for the digit to be the one found in the [0-9].
â Tinler
Jan 22 at 0:20
"sed s/[0-9]//" does the exact same as "sed s/[0-9]/00/" or am I missing something?
â Tinler
Jan 22 at 0:42
Yes. It becomes hew4r -> hew00r. I want hew44r. Also, why should I use that instead of "sed s/[0-9]/00/"? For this and the first example?
â Tinler
Jan 22 at 0:51
OK. in gnu sed usingrefers to the previously matched regex. In bsd sed this is done using
&
. So in your case sincedoes not work, you can use
sed 's/[0-9]/&&/'
. Actuall using&
will work even in gnu sed.
â George Vasiliou
Jan 22 at 1:02
1
1
How about reading the manual... You'll learn how to reference the matched portion, regardless of what's in the LHS. ;)
â don_crissti
Jan 22 at 0:13
How about reading the manual... You'll learn how to reference the matched portion, regardless of what's in the LHS. ;)
â don_crissti
Jan 22 at 0:13
My bad, I meant $sed s/[0-9]/00/ as you can see, it has to be zero. I'm looking for a way for the digit to be the one found in the [0-9].
â Tinler
Jan 22 at 0:20
My bad, I meant $sed s/[0-9]/00/ as you can see, it has to be zero. I'm looking for a way for the digit to be the one found in the [0-9].
â Tinler
Jan 22 at 0:20
"sed s/[0-9]//" does the exact same as "sed s/[0-9]/00/" or am I missing something?
â Tinler
Jan 22 at 0:42
"sed s/[0-9]//" does the exact same as "sed s/[0-9]/00/" or am I missing something?
â Tinler
Jan 22 at 0:42
Yes. It becomes hew4r -> hew00r. I want hew44r. Also, why should I use that instead of "sed s/[0-9]/00/"? For this and the first example?
â Tinler
Jan 22 at 0:51
Yes. It becomes hew4r -> hew00r. I want hew44r. Also, why should I use that instead of "sed s/[0-9]/00/"? For this and the first example?
â Tinler
Jan 22 at 0:51
OK. in gnu sed using
refers to the previously matched regex. In bsd sed this is done using &
. So in your case since
does not work, you can use sed 's/[0-9]/&&/'
. Actuall using &
will work even in gnu sed.â George Vasiliou
Jan 22 at 1:02
OK. in gnu sed using
refers to the previously matched regex. In bsd sed this is done using &
. So in your case since
does not work, you can use sed 's/[0-9]/&&/'
. Actuall using &
will work even in gnu sed.â George Vasiliou
Jan 22 at 1:02
 |Â
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You need to use the sed
's feature, called groups (may be not the best reference, try to search for other tutorials). In you case the solution is
sed 's/([0-9])/11/' input_file.txt
the regexp for the first group ([0-9])
will match any digit, and the part 11
says to replace the first group with itself repeated twice.
1
I don't think the purpose of this assignment is to teach them how to use groups. The link is good though, it has the answer.
â don_crissti
Jan 22 at 0:29
2
A lot of people helped me here answering my questions when I just began. I am just returning this help.
â John Smith
Jan 22 at 0:34
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You need to use the sed
's feature, called groups (may be not the best reference, try to search for other tutorials). In you case the solution is
sed 's/([0-9])/11/' input_file.txt
the regexp for the first group ([0-9])
will match any digit, and the part 11
says to replace the first group with itself repeated twice.
1
I don't think the purpose of this assignment is to teach them how to use groups. The link is good though, it has the answer.
â don_crissti
Jan 22 at 0:29
2
A lot of people helped me here answering my questions when I just began. I am just returning this help.
â John Smith
Jan 22 at 0:34
add a comment |Â
up vote
2
down vote
accepted
You need to use the sed
's feature, called groups (may be not the best reference, try to search for other tutorials). In you case the solution is
sed 's/([0-9])/11/' input_file.txt
the regexp for the first group ([0-9])
will match any digit, and the part 11
says to replace the first group with itself repeated twice.
1
I don't think the purpose of this assignment is to teach them how to use groups. The link is good though, it has the answer.
â don_crissti
Jan 22 at 0:29
2
A lot of people helped me here answering my questions when I just began. I am just returning this help.
â John Smith
Jan 22 at 0:34
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You need to use the sed
's feature, called groups (may be not the best reference, try to search for other tutorials). In you case the solution is
sed 's/([0-9])/11/' input_file.txt
the regexp for the first group ([0-9])
will match any digit, and the part 11
says to replace the first group with itself repeated twice.
You need to use the sed
's feature, called groups (may be not the best reference, try to search for other tutorials). In you case the solution is
sed 's/([0-9])/11/' input_file.txt
the regexp for the first group ([0-9])
will match any digit, and the part 11
says to replace the first group with itself repeated twice.
answered Jan 22 at 0:25
John Smith
95857
95857
1
I don't think the purpose of this assignment is to teach them how to use groups. The link is good though, it has the answer.
â don_crissti
Jan 22 at 0:29
2
A lot of people helped me here answering my questions when I just began. I am just returning this help.
â John Smith
Jan 22 at 0:34
add a comment |Â
1
I don't think the purpose of this assignment is to teach them how to use groups. The link is good though, it has the answer.
â don_crissti
Jan 22 at 0:29
2
A lot of people helped me here answering my questions when I just began. I am just returning this help.
â John Smith
Jan 22 at 0:34
1
1
I don't think the purpose of this assignment is to teach them how to use groups. The link is good though, it has the answer.
â don_crissti
Jan 22 at 0:29
I don't think the purpose of this assignment is to teach them how to use groups. The link is good though, it has the answer.
â don_crissti
Jan 22 at 0:29
2
2
A lot of people helped me here answering my questions when I just began. I am just returning this help.
â John Smith
Jan 22 at 0:34
A lot of people helped me here answering my questions when I just began. I am just returning this help.
â John Smith
Jan 22 at 0:34
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%2f418714%2fsed-command-that-replaces-number-and-word-by-two%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
How about reading the manual... You'll learn how to reference the matched portion, regardless of what's in the LHS. ;)
â don_crissti
Jan 22 at 0:13
My bad, I meant $sed s/[0-9]/00/ as you can see, it has to be zero. I'm looking for a way for the digit to be the one found in the [0-9].
â Tinler
Jan 22 at 0:20
"sed s/[0-9]//" does the exact same as "sed s/[0-9]/00/" or am I missing something?
â Tinler
Jan 22 at 0:42
Yes. It becomes hew4r -> hew00r. I want hew44r. Also, why should I use that instead of "sed s/[0-9]/00/"? For this and the first example?
â Tinler
Jan 22 at 0:51
OK. in gnu sed using
refers to the previously matched regex. In bsd sed this is done using
&
. So in your case sincedoes not work, you can use
sed 's/[0-9]/&&/'
. Actuall using&
will work even in gnu sed.â George Vasiliou
Jan 22 at 1:02