Replacing [0-9] with [A-J] not working with sed
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I am working on a command that replaces all digits 0-9 with their corresponding letters in sed. I know I'm doing something wrong, but sed is not interpreting the replacement regex as anything but a string literal.
The command I am using is sed -r 's/[0-9]/[A-J]/g' log > ~/output.txt
It seems pretty straightforward to me, but I have been stuck on it for about an hour. The output I receive just replaces 0-9 with the string "[A-J]"
linux command-line bash regex sed
New contributor
add a comment |Â
up vote
2
down vote
favorite
I am working on a command that replaces all digits 0-9 with their corresponding letters in sed. I know I'm doing something wrong, but sed is not interpreting the replacement regex as anything but a string literal.
The command I am using is sed -r 's/[0-9]/[A-J]/g' log > ~/output.txt
It seems pretty straightforward to me, but I have been stuck on it for about an hour. The output I receive just replaces 0-9 with the string "[A-J]"
linux command-line bash regex sed
New contributor
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am working on a command that replaces all digits 0-9 with their corresponding letters in sed. I know I'm doing something wrong, but sed is not interpreting the replacement regex as anything but a string literal.
The command I am using is sed -r 's/[0-9]/[A-J]/g' log > ~/output.txt
It seems pretty straightforward to me, but I have been stuck on it for about an hour. The output I receive just replaces 0-9 with the string "[A-J]"
linux command-line bash regex sed
New contributor
I am working on a command that replaces all digits 0-9 with their corresponding letters in sed. I know I'm doing something wrong, but sed is not interpreting the replacement regex as anything but a string literal.
The command I am using is sed -r 's/[0-9]/[A-J]/g' log > ~/output.txt
It seems pretty straightforward to me, but I have been stuck on it for about an hour. The output I receive just replaces 0-9 with the string "[A-J]"
linux command-line bash regex sed
linux command-line bash regex sed
New contributor
New contributor
New contributor
asked 3 hours ago
Matthew Snell
111
111
New contributor
New contributor
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
You want transliteration, not substitution, so replace s
with y
:
echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'
sed can't use ranges in y
, but Perl can:
echo 34031445 | perl -pe 'y/0-9/A-J/'
Or just use tr
:
echo 34031445 | tr 0-9 A-J
Agreed.tr
is the easiest and probably the fastest tool for the job.
â sdkks
21 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
You want transliteration, not substitution, so replace s
with y
:
echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'
sed can't use ranges in y
, but Perl can:
echo 34031445 | perl -pe 'y/0-9/A-J/'
Or just use tr
:
echo 34031445 | tr 0-9 A-J
Agreed.tr
is the easiest and probably the fastest tool for the job.
â sdkks
21 mins ago
add a comment |Â
up vote
3
down vote
You want transliteration, not substitution, so replace s
with y
:
echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'
sed can't use ranges in y
, but Perl can:
echo 34031445 | perl -pe 'y/0-9/A-J/'
Or just use tr
:
echo 34031445 | tr 0-9 A-J
Agreed.tr
is the easiest and probably the fastest tool for the job.
â sdkks
21 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You want transliteration, not substitution, so replace s
with y
:
echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'
sed can't use ranges in y
, but Perl can:
echo 34031445 | perl -pe 'y/0-9/A-J/'
Or just use tr
:
echo 34031445 | tr 0-9 A-J
You want transliteration, not substitution, so replace s
with y
:
echo 34031445 | sed 'y/0123456789/ABCDEFGHIJ/'
sed can't use ranges in y
, but Perl can:
echo 34031445 | perl -pe 'y/0-9/A-J/'
Or just use tr
:
echo 34031445 | tr 0-9 A-J
answered 3 hours ago
choroba
12.5k12838
12.5k12838
Agreed.tr
is the easiest and probably the fastest tool for the job.
â sdkks
21 mins ago
add a comment |Â
Agreed.tr
is the easiest and probably the fastest tool for the job.
â sdkks
21 mins ago
Agreed.
tr
is the easiest and probably the fastest tool for the job.â sdkks
21 mins ago
Agreed.
tr
is the easiest and probably the fastest tool for the job.â sdkks
21 mins ago
add a comment |Â
Matthew Snell is a new contributor. Be nice, and check out our Code of Conduct.
Matthew Snell is a new contributor. Be nice, and check out our Code of Conduct.
Matthew Snell is a new contributor. Be nice, and check out our Code of Conduct.
Matthew Snell 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%2fsuperuser.com%2fquestions%2f1368784%2freplacing-0-9-with-a-j-not-working-with-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