Regular expression to match only last folder [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
This question already has an answer here:
How do $0##*/ and $0%/* work?
1 answer
How to get last part of http link in Bash?
5 answers
Extracting filename from path string
1 answer
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?
This question is a little different than How to get last part of http link in Bash? and Extracting filename from path string because I am trying to get the last folder not file or http link which have a different pattern (For those sed 's//.*// !'
should work too.) Basename is what I was looking for.
linux bash text-processing sed regular-expression
marked as duplicate by don_crissti, Goro, Romeo Ninov, G-Man, Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
49 secs ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
This question already has an answer here:
How do $0##*/ and $0%/* work?
1 answer
How to get last part of http link in Bash?
5 answers
Extracting filename from path string
1 answer
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?
This question is a little different than How to get last part of http link in Bash? and Extracting filename from path string because I am trying to get the last folder not file or http link which have a different pattern (For those sed 's//.*// !'
should work too.) Basename is what I was looking for.
linux bash text-processing sed regular-expression
marked as duplicate by don_crissti, Goro, Romeo Ninov, G-Man, Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
49 secs ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
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
27 mins ago
2
or Extracting filename from path string etc... there are many similar or related questions (like dozens...)
â don_crissti
21 mins ago
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
How do $0##*/ and $0%/* work?
1 answer
How to get last part of http link in Bash?
5 answers
Extracting filename from path string
1 answer
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?
This question is a little different than How to get last part of http link in Bash? and Extracting filename from path string because I am trying to get the last folder not file or http link which have a different pattern (For those sed 's//.*// !'
should work too.) Basename is what I was looking for.
linux bash text-processing sed regular-expression
This question already has an answer here:
How do $0##*/ and $0%/* work?
1 answer
How to get last part of http link in Bash?
5 answers
Extracting filename from path string
1 answer
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?
This question is a little different than How to get last part of http link in Bash? and Extracting filename from path string because I am trying to get the last folder not file or http link which have a different pattern (For those sed 's//.*// !'
should work too.) Basename is what I was looking for.
This question already has an answer here:
How do $0##*/ and $0%/* work?
1 answer
How to get last part of http link in Bash?
5 answers
Extracting filename from path string
1 answer
linux bash text-processing sed regular-expression
linux bash text-processing sed regular-expression
edited 1 min ago
Kusalananda
109k14213336
109k14213336
asked 30 mins ago
novice
205
205
marked as duplicate by don_crissti, Goro, Romeo Ninov, G-Man, Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
49 secs ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by don_crissti, Goro, Romeo Ninov, G-Man, Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
49 secs ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
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
27 mins ago
2
or Extracting filename from path string etc... there are many similar or related questions (like dozens...)
â don_crissti
21 mins ago
add a comment |Â
2
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
27 mins ago
2
or Extracting filename from path string etc... there are many similar or related questions (like dozens...)
â don_crissti
21 mins ago
2
2
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
27 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
27 mins ago
2
2
or Extracting filename from path string etc... there are many similar or related questions (like dozens...)
â don_crissti
21 mins ago
or Extracting filename from path string etc... there are many similar or related questions (like dozens...)
â don_crissti
21 mins ago
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
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
27 mins ago
2
or Extracting filename from path string etc... there are many similar or related questions (like dozens...)
â don_crissti
21 mins ago