Regular expression to match only last folder
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I would like to get the name of the last folder in a path for use in bash script.
For example: I have a path /media/devicename/folder1/
I would like to get a variable called foldername
that has in it the word folder1
. If I do sed 's//.*/$//' /media/devicename/folder1/
that matches the entire line. How can I limit the regular expression to only the first occurrence of the backslash?
linux bash text-processing sed regular-expression
add a comment |Â
up vote
0
down vote
favorite
I would like to get the name of the last folder in a path for use in bash script.
For example: I have a path /media/devicename/folder1/
I would like to get a variable called foldername
that has in it the word folder1
. If I do sed 's//.*/$//' /media/devicename/folder1/
that matches the entire line. How can I limit the regular expression to only the first occurrence of the backslash?
linux bash text-processing sed regular-expression
Hello @novice if you want the last folder name you can usebasename
, you don't need regular expression for that? I meanbasename /media/devicename/folder1/
==>folder1
â Goro
2 mins ago
Possible duplicate of How to get last part of http link in Bash?
â don_crissti
2 mins ago
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I would like to get the name of the last folder in a path for use in bash script.
For example: I have a path /media/devicename/folder1/
I would like to get a variable called foldername
that has in it the word folder1
. If I do sed 's//.*/$//' /media/devicename/folder1/
that matches the entire line. How can I limit the regular expression to only the first occurrence of the backslash?
linux bash text-processing sed regular-expression
I would like to get the name of the last folder in a path for use in bash script.
For example: I have a path /media/devicename/folder1/
I would like to get a variable called foldername
that has in it the word folder1
. If I do sed 's//.*/$//' /media/devicename/folder1/
that matches the entire line. How can I limit the regular expression to only the first occurrence of the backslash?
linux bash text-processing sed regular-expression
linux bash text-processing sed regular-expression
asked 6 mins ago
novice
205
205
Hello @novice if you want the last folder name you can usebasename
, you don't need regular expression for that? I meanbasename /media/devicename/folder1/
==>folder1
â Goro
2 mins ago
Possible duplicate of How to get last part of http link in Bash?
â don_crissti
2 mins ago
add a comment |Â
Hello @novice if you want the last folder name you can usebasename
, you don't need regular expression for that? I meanbasename /media/devicename/folder1/
==>folder1
â Goro
2 mins ago
Possible duplicate of How to get last part of http link in Bash?
â don_crissti
2 mins ago
Hello @novice if you want the last folder name you can use
basename
, you don't need regular expression for that? I mean basename /media/devicename/folder1/
==> folder1
â Goro
2 mins ago
Hello @novice if you want the last folder name you can use
basename
, you don't need regular expression for that? I mean basename /media/devicename/folder1/
==> folder1
â Goro
2 mins ago
Possible duplicate of How to get last part of http link in Bash?
â don_crissti
2 mins ago
Possible duplicate of How to get last part of http link in Bash?
â don_crissti
2 mins ago
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f475464%2fregular-expression-to-match-only-last-folder%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
Hello @novice if you want the last folder name you can use
basename
, you don't need regular expression for that? I meanbasename /media/devicename/folder1/
==>folder1
â Goro
2 mins ago
Possible duplicate of How to get last part of http link in Bash?
â don_crissti
2 mins ago