To remove the second last character from a string
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I've a string something like this: abdh0chjkj0g
.
I want to delete the second last character only if it is a 0
.
I know sed
and awk
would do the work..but i'm unable to get the exact command for this.
Any help?
awk sed
add a comment |Â
up vote
0
down vote
favorite
I've a string something like this: abdh0chjkj0g
.
I want to delete the second last character only if it is a 0
.
I know sed
and awk
would do the work..but i'm unable to get the exact command for this.
Any help?
awk sed
Should all zeros be removed fromrcaoe0aoea0o
and allB
fromaoBoaeBo
? or is only the second to last character or zeros in general?
â Kusalananda
Apr 2 at 11:48
Hi, Only the 'zero' present in the second last position needs to be removed. Thanks
â User123
Apr 2 at 11:49
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've a string something like this: abdh0chjkj0g
.
I want to delete the second last character only if it is a 0
.
I know sed
and awk
would do the work..but i'm unable to get the exact command for this.
Any help?
awk sed
I've a string something like this: abdh0chjkj0g
.
I want to delete the second last character only if it is a 0
.
I know sed
and awk
would do the work..but i'm unable to get the exact command for this.
Any help?
awk sed
edited Apr 2 at 11:53
cunninghamp3
473215
473215
asked Apr 2 at 11:40
User123
577
577
Should all zeros be removed fromrcaoe0aoea0o
and allB
fromaoBoaeBo
? or is only the second to last character or zeros in general?
â Kusalananda
Apr 2 at 11:48
Hi, Only the 'zero' present in the second last position needs to be removed. Thanks
â User123
Apr 2 at 11:49
add a comment |Â
Should all zeros be removed fromrcaoe0aoea0o
and allB
fromaoBoaeBo
? or is only the second to last character or zeros in general?
â Kusalananda
Apr 2 at 11:48
Hi, Only the 'zero' present in the second last position needs to be removed. Thanks
â User123
Apr 2 at 11:49
Should all zeros be removed from
rcaoe0aoea0o
and all B
from aoBoaeBo
? or is only the second to last character or zeros in general?â Kusalananda
Apr 2 at 11:48
Should all zeros be removed from
rcaoe0aoea0o
and all B
from aoBoaeBo
? or is only the second to last character or zeros in general?â Kusalananda
Apr 2 at 11:48
Hi, Only the 'zero' present in the second last position needs to be removed. Thanks
â User123
Apr 2 at 11:49
Hi, Only the 'zero' present in the second last position needs to be removed. Thanks
â User123
Apr 2 at 11:49
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Using sed :
$ echo 'abdhchjkj0g' | sed 's/0(.)$/1/'
Using perl :
$ echo 'abdhchjkj0g' | perl -pe 's/0(?=.$)//'
Using gnuawk :
$ echo 'abdhchjkj0g' | awk 'print gensub(/0(.)$/, "\1", "1")'
abdhchjkjg
I don't think this quite does what is asked for yet (I think because the example doesn't match the question) - you'll need to pull all0
s to match the question. For example, I think,dsgf0dsfads0d0d
would need to becomedsgfdsfadsdd
â cunninghamp3
Apr 2 at 11:46
OP says : the second last character
â Gilles Quenot
Apr 2 at 11:48
Then continues to say "from the string everytime it appears"
â cunninghamp3
Apr 2 at 11:50
And, as far as I can interpret his comment, only if it is a zero.
â Kusalananda
Apr 2 at 11:51
1
@Giles: Yeah :-) now all fine.Thanks
â User123
Apr 2 at 12:08
 |Â
show 4 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Using sed :
$ echo 'abdhchjkj0g' | sed 's/0(.)$/1/'
Using perl :
$ echo 'abdhchjkj0g' | perl -pe 's/0(?=.$)//'
Using gnuawk :
$ echo 'abdhchjkj0g' | awk 'print gensub(/0(.)$/, "\1", "1")'
abdhchjkjg
I don't think this quite does what is asked for yet (I think because the example doesn't match the question) - you'll need to pull all0
s to match the question. For example, I think,dsgf0dsfads0d0d
would need to becomedsgfdsfadsdd
â cunninghamp3
Apr 2 at 11:46
OP says : the second last character
â Gilles Quenot
Apr 2 at 11:48
Then continues to say "from the string everytime it appears"
â cunninghamp3
Apr 2 at 11:50
And, as far as I can interpret his comment, only if it is a zero.
â Kusalananda
Apr 2 at 11:51
1
@Giles: Yeah :-) now all fine.Thanks
â User123
Apr 2 at 12:08
 |Â
show 4 more comments
up vote
2
down vote
accepted
Using sed :
$ echo 'abdhchjkj0g' | sed 's/0(.)$/1/'
Using perl :
$ echo 'abdhchjkj0g' | perl -pe 's/0(?=.$)//'
Using gnuawk :
$ echo 'abdhchjkj0g' | awk 'print gensub(/0(.)$/, "\1", "1")'
abdhchjkjg
I don't think this quite does what is asked for yet (I think because the example doesn't match the question) - you'll need to pull all0
s to match the question. For example, I think,dsgf0dsfads0d0d
would need to becomedsgfdsfadsdd
â cunninghamp3
Apr 2 at 11:46
OP says : the second last character
â Gilles Quenot
Apr 2 at 11:48
Then continues to say "from the string everytime it appears"
â cunninghamp3
Apr 2 at 11:50
And, as far as I can interpret his comment, only if it is a zero.
â Kusalananda
Apr 2 at 11:51
1
@Giles: Yeah :-) now all fine.Thanks
â User123
Apr 2 at 12:08
 |Â
show 4 more comments
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Using sed :
$ echo 'abdhchjkj0g' | sed 's/0(.)$/1/'
Using perl :
$ echo 'abdhchjkj0g' | perl -pe 's/0(?=.$)//'
Using gnuawk :
$ echo 'abdhchjkj0g' | awk 'print gensub(/0(.)$/, "\1", "1")'
abdhchjkjg
Using sed :
$ echo 'abdhchjkj0g' | sed 's/0(.)$/1/'
Using perl :
$ echo 'abdhchjkj0g' | perl -pe 's/0(?=.$)//'
Using gnuawk :
$ echo 'abdhchjkj0g' | awk 'print gensub(/0(.)$/, "\1", "1")'
abdhchjkjg
edited Apr 2 at 12:09
answered Apr 2 at 11:43
Gilles Quenot
15.3k13448
15.3k13448
I don't think this quite does what is asked for yet (I think because the example doesn't match the question) - you'll need to pull all0
s to match the question. For example, I think,dsgf0dsfads0d0d
would need to becomedsgfdsfadsdd
â cunninghamp3
Apr 2 at 11:46
OP says : the second last character
â Gilles Quenot
Apr 2 at 11:48
Then continues to say "from the string everytime it appears"
â cunninghamp3
Apr 2 at 11:50
And, as far as I can interpret his comment, only if it is a zero.
â Kusalananda
Apr 2 at 11:51
1
@Giles: Yeah :-) now all fine.Thanks
â User123
Apr 2 at 12:08
 |Â
show 4 more comments
I don't think this quite does what is asked for yet (I think because the example doesn't match the question) - you'll need to pull all0
s to match the question. For example, I think,dsgf0dsfads0d0d
would need to becomedsgfdsfadsdd
â cunninghamp3
Apr 2 at 11:46
OP says : the second last character
â Gilles Quenot
Apr 2 at 11:48
Then continues to say "from the string everytime it appears"
â cunninghamp3
Apr 2 at 11:50
And, as far as I can interpret his comment, only if it is a zero.
â Kusalananda
Apr 2 at 11:51
1
@Giles: Yeah :-) now all fine.Thanks
â User123
Apr 2 at 12:08
I don't think this quite does what is asked for yet (I think because the example doesn't match the question) - you'll need to pull all
0
s to match the question. For example, I think, dsgf0dsfads0d0d
would need to become dsgfdsfadsdd
â cunninghamp3
Apr 2 at 11:46
I don't think this quite does what is asked for yet (I think because the example doesn't match the question) - you'll need to pull all
0
s to match the question. For example, I think, dsgf0dsfads0d0d
would need to become dsgfdsfadsdd
â cunninghamp3
Apr 2 at 11:46
OP says : the second last character
â Gilles Quenot
Apr 2 at 11:48
OP says : the second last character
â Gilles Quenot
Apr 2 at 11:48
Then continues to say "from the string everytime it appears"
â cunninghamp3
Apr 2 at 11:50
Then continues to say "from the string everytime it appears"
â cunninghamp3
Apr 2 at 11:50
And, as far as I can interpret his comment, only if it is a zero.
â Kusalananda
Apr 2 at 11:51
And, as far as I can interpret his comment, only if it is a zero.
â Kusalananda
Apr 2 at 11:51
1
1
@Giles: Yeah :-) now all fine.Thanks
â User123
Apr 2 at 12:08
@Giles: Yeah :-) now all fine.Thanks
â User123
Apr 2 at 12:08
 |Â
show 4 more comments
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%2f435031%2fto-remove-the-second-last-character-from-a-string%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
Should all zeros be removed from
rcaoe0aoea0o
and allB
fromaoBoaeBo
? or is only the second to last character or zeros in general?â Kusalananda
Apr 2 at 11:48
Hi, Only the 'zero' present in the second last position needs to be removed. Thanks
â User123
Apr 2 at 11:49