How can I delete the characters before "/", including the "/", in a string using Perl or sed?
For instance, this:
ad9a91/FFFF0000
would turn into
FFFF0000
How can I delete the characters before "/", including the "/", in a string using Perl or sed?
For instance, this:
ad9a91/FFFF0000
would turn into
FFFF0000
Sed solution
sed 's|[^/]*/||' file
Will remove everything up to and including the first /
or
sed 's|.*/||' file
Will remove everything up to and including the last /
.
I added both as the question was not entirely clear on what the format of the string would be every time.
Awk
awk -F/ '{$0=$NF}1' file
This replaces the entire line with whatever is after the last /
You can use substitution,
my $str = "ad9a91/FFFF0000";
$str =~ s|^.+?/||;
or regex capture,
$str = $1 if $str =~ m|/(.+)|s;
Use substitution for this:
my $string = "ad9a91/FFFF0000";
$string =~ s|\.+/||;
my $string = qq(sjdflksdjfsdj ad9a91/FFFF0000 slodjfsdf s);
$string =~ s{\b(\s).*?\b/}{$1}ig;
print $string;exit;
you can also try this split with any space or any tag.