Cutting all the characters after the last /
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
8
down vote
favorite
How do I cut all characters after the last '/'?
This text
xxxx/x/xx/xx/xxxx/x/yyyyy
xxx/xxxx/xxxxx/yyy
should return
xxxx/x/xx/xx/xxxx/x
xxx/xxxx/xxxxx
command-line text-processing
 |Â
show 1 more comment
up vote
8
down vote
favorite
How do I cut all characters after the last '/'?
This text
xxxx/x/xx/xx/xxxx/x/yyyyy
xxx/xxxx/xxxxx/yyy
should return
xxxx/x/xx/xx/xxxx/x
xxx/xxxx/xxxxx
command-line text-processing
4
Are you trying to omit or isolate the characters after the last/
?
â dsstorefile1
Feb 27 at 15:34
Good question, I just realised that we didn't understand the question the same way
â Félicien
Feb 27 at 15:35
3
The commandsbasename
anddirname
do this already.
â Michael Hampton
Feb 28 at 0:49
I don't think edit #5 to the question was correct. Using the word "cut" might be ambiguous; if you cut something, do you throw away that part, or do you keep only that? However, the previous wording "and to omit what is before the /" was unambiguous. This was changed to its opposite.
â egmont
Mar 1 at 0:02
@egmont the word "cut" itself was carried over from the original: "I need to cut only the charachters after the last/
" became "How do I cut all characters after the last '/'?" which is a change of phrasing that reasonably keeps the meaning, IMO. If anything, I felt the "omit what is ..." part ambiguous: the examples seem to keep what is before the/
. The example, makes it clear, anyway.
â muru
Mar 1 at 4:30
 |Â
show 1 more comment
up vote
8
down vote
favorite
up vote
8
down vote
favorite
How do I cut all characters after the last '/'?
This text
xxxx/x/xx/xx/xxxx/x/yyyyy
xxx/xxxx/xxxxx/yyy
should return
xxxx/x/xx/xx/xxxx/x
xxx/xxxx/xxxxx
command-line text-processing
How do I cut all characters after the last '/'?
This text
xxxx/x/xx/xx/xxxx/x/yyyyy
xxx/xxxx/xxxxx/yyy
should return
xxxx/x/xx/xx/xxxx/x
xxx/xxxx/xxxxx
command-line text-processing
command-line text-processing
edited Feb 28 at 3:57
muru
130k19274467
130k19274467
asked Feb 27 at 15:27
Josef Klimuk
542112
542112
4
Are you trying to omit or isolate the characters after the last/
?
â dsstorefile1
Feb 27 at 15:34
Good question, I just realised that we didn't understand the question the same way
â Félicien
Feb 27 at 15:35
3
The commandsbasename
anddirname
do this already.
â Michael Hampton
Feb 28 at 0:49
I don't think edit #5 to the question was correct. Using the word "cut" might be ambiguous; if you cut something, do you throw away that part, or do you keep only that? However, the previous wording "and to omit what is before the /" was unambiguous. This was changed to its opposite.
â egmont
Mar 1 at 0:02
@egmont the word "cut" itself was carried over from the original: "I need to cut only the charachters after the last/
" became "How do I cut all characters after the last '/'?" which is a change of phrasing that reasonably keeps the meaning, IMO. If anything, I felt the "omit what is ..." part ambiguous: the examples seem to keep what is before the/
. The example, makes it clear, anyway.
â muru
Mar 1 at 4:30
 |Â
show 1 more comment
4
Are you trying to omit or isolate the characters after the last/
?
â dsstorefile1
Feb 27 at 15:34
Good question, I just realised that we didn't understand the question the same way
â Félicien
Feb 27 at 15:35
3
The commandsbasename
anddirname
do this already.
â Michael Hampton
Feb 28 at 0:49
I don't think edit #5 to the question was correct. Using the word "cut" might be ambiguous; if you cut something, do you throw away that part, or do you keep only that? However, the previous wording "and to omit what is before the /" was unambiguous. This was changed to its opposite.
â egmont
Mar 1 at 0:02
@egmont the word "cut" itself was carried over from the original: "I need to cut only the charachters after the last/
" became "How do I cut all characters after the last '/'?" which is a change of phrasing that reasonably keeps the meaning, IMO. If anything, I felt the "omit what is ..." part ambiguous: the examples seem to keep what is before the/
. The example, makes it clear, anyway.
â muru
Mar 1 at 4:30
4
4
Are you trying to omit or isolate the characters after the last
/
?â dsstorefile1
Feb 27 at 15:34
Are you trying to omit or isolate the characters after the last
/
?â dsstorefile1
Feb 27 at 15:34
Good question, I just realised that we didn't understand the question the same way
â Félicien
Feb 27 at 15:35
Good question, I just realised that we didn't understand the question the same way
â Félicien
Feb 27 at 15:35
3
3
The commands
basename
and dirname
do this already.â Michael Hampton
Feb 28 at 0:49
The commands
basename
and dirname
do this already.â Michael Hampton
Feb 28 at 0:49
I don't think edit #5 to the question was correct. Using the word "cut" might be ambiguous; if you cut something, do you throw away that part, or do you keep only that? However, the previous wording "and to omit what is before the /" was unambiguous. This was changed to its opposite.
â egmont
Mar 1 at 0:02
I don't think edit #5 to the question was correct. Using the word "cut" might be ambiguous; if you cut something, do you throw away that part, or do you keep only that? However, the previous wording "and to omit what is before the /" was unambiguous. This was changed to its opposite.
â egmont
Mar 1 at 0:02
@egmont the word "cut" itself was carried over from the original: "I need to cut only the charachters after the last
/
" became "How do I cut all characters after the last '/'?" which is a change of phrasing that reasonably keeps the meaning, IMO. If anything, I felt the "omit what is ..." part ambiguous: the examples seem to keep what is before the /
. The example, makes it clear, anyway.â muru
Mar 1 at 4:30
@egmont the word "cut" itself was carried over from the original: "I need to cut only the charachters after the last
/
" became "How do I cut all characters after the last '/'?" which is a change of phrasing that reasonably keeps the meaning, IMO. If anything, I felt the "omit what is ..." part ambiguous: the examples seem to keep what is before the /
. The example, makes it clear, anyway.â muru
Mar 1 at 4:30
 |Â
show 1 more comment
7 Answers
7
active
oldest
votes
up vote
10
down vote
accepted
If you want to get the "cutted part"
yyy
yyyyy
You can use
sed 's|.*/||'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|.*/||'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|.*/||'
output
yyy
yyyyy
(Note: This uses the ability of sed to use a separator other than /, in this case |, in the s command)
If you want to get the begining of the string :
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
You can use
sed 's|(.*)/.*|1|'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|(.*)/.*|1|'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|(.*)/.*|1|'
output
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
5
Hi, in this case you can change the delimiter, for example#
instead of/
. Also you can use the option-r
if you don't want to escape ` ` each special character:sed -r 's#(^.*)/.*$#1#'
.
â pa4080
Feb 27 at 15:49
1
I have submitted a proposed edit to use | instead of /. If you don't like it, I suggest you "reject and edit" it, and change "begginning" to "beginning". (Reject+Edit, because that way it won't get approved by robo-approvers. Alternatively, just roll the change back if it has got approved and you didn't like it.)
â Martin Bonner
Mar 1 at 6:33
add a comment |Â
up vote
18
down vote
If you're cutting off the ends of the strings,dirname
might fit the bill:
$ dirname xxxx/x/xx/xx/xxxx/x/yyyyy
xxxx/x/xx/xx/xxxx/x
$ _
If you're trying to isolate the last part of the string, use echo /$(basename "$str")
.
$ str=xxxx/x/xx/xx/xxxx/x/yyyyy
$ echo /$(basename "$str")
/yyyyy
$ _
2
Honestly, why anyone would either suggest or accept an answer involving sed (or awk, or any other similar method) instead of just using the utilities installed with the OS is beyond me.
â Auspex
Feb 28 at 11:48
@Auspex I'd guess it's simply becausedirname
andbasename
are not widely known, butsed
andawk
are.
â Volker Siegel
Feb 28 at 13:08
add a comment |Â
up vote
15
down vote
Parameter expansion in bash
You can use parameter expansion in bash
, in this case
$parameter%word
whereword
is/*
$parameter##word
whereword
is*/
Examples:
Remove the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf%/*
xxx/xxxx/xxxxx
This is described in man bash
:
$parameter%word
$parameter%%word
Remove matching suffix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with
the shortest matching pattern (the ``%'' case) or the longest
matching pattern (the ``%%'' case) deleted. If parameter is @
or *, the pattern removal operation is applied to each posiâÂÂ
tional parameter in turn, and the expansion is the resultant
list. If parameter is an array variable subscripted with @ or
*, the pattern removal operation is applied to each member of
the array in turn, and the expansion is the resultant list.
Remove all except the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf##*/
yyy
You can add a slash like so
$ echo /$asdf##*/
/yyy
to get exactly what you wanted at one particular instance according to the edited question. But the question has been edited by several people after that and it is not easy to know what you want now.
This is described in man bash
:
$parameter#word
$parameter##word
Remove matching prefix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
the beginning of the value of parameter, then the result of the
expansion is the expanded value of parameter with the shortest
matching pattern (the ``#'' case) or the longest matching patâÂÂ
tern (the ``##'' case) deleted. If parameter is @ or *, the
pattern removal operation is applied to each positional parameâÂÂ
ter in turn, and the expansion is the resultant list. If paramâÂÂ
eter is an array variable subscripted with @ or *, the pattern
removal operation is applied to each member of the array in
turn, and the expansion is the resultant list.
add a comment |Â
up vote
9
down vote
Another way is to use grep
to only display the last slash per line and whatever follows it:
$ grep -o '/[^/]*$' example.txt
/yyy
/yyyyy
Explanation:
-o
tells grep
to only show the matching part of the line instead of the whole line.
The pattern /[^/]*$
matches a literal slash /
followed by any character except for a slash [^/]
any number of times *
until the end of the line $
.
add a comment |Â
up vote
7
down vote
Just because others have posted more âÂÂsaneâ answers, hereâÂÂs a somewhat silly one:
rev | cut -d/ -f1 | rev
rev
reverses the characters in each line, e.g. abcd/ef/g
becomes g/fe/dcba
. Then cut
cuts out the first segment. Finally itâÂÂs reversed again.
1
Despite the non-sanity of this answer, especially because of the shell plumbing, I like this answer :) Keep on rocking, +1
â Sergiy Kolodyazhnyy
Feb 28 at 2:32
Agreed - not sane, but badass!
â Volker Siegel
Feb 28 at 12:12
add a comment |Â
up vote
3
down vote
Classic solution with awk
, that treats /
as field separator for both input and output and sets the last field to empty string ( which really is "dereferencing" of the number of fields NF
variable ):
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";$NF="";print $0'
xxx/xxxx/xxxxx/
Shorter, as fedorqui pointed out in the comments:
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";NF--'
xxx/xxxx/xxxxx/
Variation on that would be to put path into awk
's execution environment, which will save up on plumbing but makes awk
portion more verbose:
mypath="xxx/xxxx/xxxxx/yyy" awk 'BEGINOFS=FS="/"; sub(//([^/]*)$/,"",ENVIRON["mypath"]);print(ENVIRON["mypath"]) ;'
1
Too verbose, why not justNF--
? This way you avoud theprint
bla bla.
â fedorqui
Feb 28 at 9:35
add a comment |Â
up vote
2
down vote
Adding to egmont's answer because the question has been edited...
Use --complement if you want to remove the first field with -f1.
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1 --complement|rev
xxxx/x/xx/xx/xxxx/x
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1|rev
yyyyy
Also, the question isn't quite clear about what should happen with inputs not containing any slashes.
xxxx => xxxx
or
xxxx => nothing
You can suggest an edit to it: askubuntu.com/posts/1010356/edit
â muru
Feb 28 at 14:08
@muru OP is 1 rep user. Isn't editing privilege is granted at 2k ? askubuntu.com/help/privileges/edit
â Sergiy Kolodyazhnyy
Feb 28 at 18:47
@SergiyKolodyazhnyy anybody can suggest edits.
â muru
Feb 28 at 21:26
+1 - I had not noticed the--complement
option before and the man page is circular. Complement means complement. I found a nice cut tutorial which covers it at yourownlinux.com/2015/05/⦠It's like-v
ingrep
. Give me everything except what was matched.
â Joe
Feb 28 at 23:59
1
-f2-
is a simpler form for-f1 --complement
.
â egmont
Mar 1 at 0:04
add a comment |Â
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
accepted
If you want to get the "cutted part"
yyy
yyyyy
You can use
sed 's|.*/||'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|.*/||'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|.*/||'
output
yyy
yyyyy
(Note: This uses the ability of sed to use a separator other than /, in this case |, in the s command)
If you want to get the begining of the string :
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
You can use
sed 's|(.*)/.*|1|'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|(.*)/.*|1|'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|(.*)/.*|1|'
output
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
5
Hi, in this case you can change the delimiter, for example#
instead of/
. Also you can use the option-r
if you don't want to escape ` ` each special character:sed -r 's#(^.*)/.*$#1#'
.
â pa4080
Feb 27 at 15:49
1
I have submitted a proposed edit to use | instead of /. If you don't like it, I suggest you "reject and edit" it, and change "begginning" to "beginning". (Reject+Edit, because that way it won't get approved by robo-approvers. Alternatively, just roll the change back if it has got approved and you didn't like it.)
â Martin Bonner
Mar 1 at 6:33
add a comment |Â
up vote
10
down vote
accepted
If you want to get the "cutted part"
yyy
yyyyy
You can use
sed 's|.*/||'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|.*/||'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|.*/||'
output
yyy
yyyyy
(Note: This uses the ability of sed to use a separator other than /, in this case |, in the s command)
If you want to get the begining of the string :
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
You can use
sed 's|(.*)/.*|1|'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|(.*)/.*|1|'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|(.*)/.*|1|'
output
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
5
Hi, in this case you can change the delimiter, for example#
instead of/
. Also you can use the option-r
if you don't want to escape ` ` each special character:sed -r 's#(^.*)/.*$#1#'
.
â pa4080
Feb 27 at 15:49
1
I have submitted a proposed edit to use | instead of /. If you don't like it, I suggest you "reject and edit" it, and change "begginning" to "beginning". (Reject+Edit, because that way it won't get approved by robo-approvers. Alternatively, just roll the change back if it has got approved and you didn't like it.)
â Martin Bonner
Mar 1 at 6:33
add a comment |Â
up vote
10
down vote
accepted
up vote
10
down vote
accepted
If you want to get the "cutted part"
yyy
yyyyy
You can use
sed 's|.*/||'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|.*/||'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|.*/||'
output
yyy
yyyyy
(Note: This uses the ability of sed to use a separator other than /, in this case |, in the s command)
If you want to get the begining of the string :
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
You can use
sed 's|(.*)/.*|1|'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|(.*)/.*|1|'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|(.*)/.*|1|'
output
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
If you want to get the "cutted part"
yyy
yyyyy
You can use
sed 's|.*/||'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|.*/||'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|.*/||'
output
yyy
yyyyy
(Note: This uses the ability of sed to use a separator other than /, in this case |, in the s command)
If you want to get the begining of the string :
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
You can use
sed 's|(.*)/.*|1|'
eg.
echo "xxx/xxxx/xxxxx/yyy" | sed 's|(.*)/.*|1|'
echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|(.*)/.*|1|'
output
xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
edited Mar 1 at 8:40
Martin Bonner
1034
1034
answered Feb 27 at 15:30
Félicien
8471516
8471516
5
Hi, in this case you can change the delimiter, for example#
instead of/
. Also you can use the option-r
if you don't want to escape ` ` each special character:sed -r 's#(^.*)/.*$#1#'
.
â pa4080
Feb 27 at 15:49
1
I have submitted a proposed edit to use | instead of /. If you don't like it, I suggest you "reject and edit" it, and change "begginning" to "beginning". (Reject+Edit, because that way it won't get approved by robo-approvers. Alternatively, just roll the change back if it has got approved and you didn't like it.)
â Martin Bonner
Mar 1 at 6:33
add a comment |Â
5
Hi, in this case you can change the delimiter, for example#
instead of/
. Also you can use the option-r
if you don't want to escape ` ` each special character:sed -r 's#(^.*)/.*$#1#'
.
â pa4080
Feb 27 at 15:49
1
I have submitted a proposed edit to use | instead of /. If you don't like it, I suggest you "reject and edit" it, and change "begginning" to "beginning". (Reject+Edit, because that way it won't get approved by robo-approvers. Alternatively, just roll the change back if it has got approved and you didn't like it.)
â Martin Bonner
Mar 1 at 6:33
5
5
Hi, in this case you can change the delimiter, for example
#
instead of /
. Also you can use the option -r
if you don't want to escape ` ` each special character: sed -r 's#(^.*)/.*$#1#'
.â pa4080
Feb 27 at 15:49
Hi, in this case you can change the delimiter, for example
#
instead of /
. Also you can use the option -r
if you don't want to escape ` ` each special character: sed -r 's#(^.*)/.*$#1#'
.â pa4080
Feb 27 at 15:49
1
1
I have submitted a proposed edit to use | instead of /. If you don't like it, I suggest you "reject and edit" it, and change "begginning" to "beginning". (Reject+Edit, because that way it won't get approved by robo-approvers. Alternatively, just roll the change back if it has got approved and you didn't like it.)
â Martin Bonner
Mar 1 at 6:33
I have submitted a proposed edit to use | instead of /. If you don't like it, I suggest you "reject and edit" it, and change "begginning" to "beginning". (Reject+Edit, because that way it won't get approved by robo-approvers. Alternatively, just roll the change back if it has got approved and you didn't like it.)
â Martin Bonner
Mar 1 at 6:33
add a comment |Â
up vote
18
down vote
If you're cutting off the ends of the strings,dirname
might fit the bill:
$ dirname xxxx/x/xx/xx/xxxx/x/yyyyy
xxxx/x/xx/xx/xxxx/x
$ _
If you're trying to isolate the last part of the string, use echo /$(basename "$str")
.
$ str=xxxx/x/xx/xx/xxxx/x/yyyyy
$ echo /$(basename "$str")
/yyyyy
$ _
2
Honestly, why anyone would either suggest or accept an answer involving sed (or awk, or any other similar method) instead of just using the utilities installed with the OS is beyond me.
â Auspex
Feb 28 at 11:48
@Auspex I'd guess it's simply becausedirname
andbasename
are not widely known, butsed
andawk
are.
â Volker Siegel
Feb 28 at 13:08
add a comment |Â
up vote
18
down vote
If you're cutting off the ends of the strings,dirname
might fit the bill:
$ dirname xxxx/x/xx/xx/xxxx/x/yyyyy
xxxx/x/xx/xx/xxxx/x
$ _
If you're trying to isolate the last part of the string, use echo /$(basename "$str")
.
$ str=xxxx/x/xx/xx/xxxx/x/yyyyy
$ echo /$(basename "$str")
/yyyyy
$ _
2
Honestly, why anyone would either suggest or accept an answer involving sed (or awk, or any other similar method) instead of just using the utilities installed with the OS is beyond me.
â Auspex
Feb 28 at 11:48
@Auspex I'd guess it's simply becausedirname
andbasename
are not widely known, butsed
andawk
are.
â Volker Siegel
Feb 28 at 13:08
add a comment |Â
up vote
18
down vote
up vote
18
down vote
If you're cutting off the ends of the strings,dirname
might fit the bill:
$ dirname xxxx/x/xx/xx/xxxx/x/yyyyy
xxxx/x/xx/xx/xxxx/x
$ _
If you're trying to isolate the last part of the string, use echo /$(basename "$str")
.
$ str=xxxx/x/xx/xx/xxxx/x/yyyyy
$ echo /$(basename "$str")
/yyyyy
$ _
If you're cutting off the ends of the strings,dirname
might fit the bill:
$ dirname xxxx/x/xx/xx/xxxx/x/yyyyy
xxxx/x/xx/xx/xxxx/x
$ _
If you're trying to isolate the last part of the string, use echo /$(basename "$str")
.
$ str=xxxx/x/xx/xx/xxxx/x/yyyyy
$ echo /$(basename "$str")
/yyyyy
$ _
edited Feb 27 at 15:39
answered Feb 27 at 15:33
dsstorefile1
1,312111
1,312111
2
Honestly, why anyone would either suggest or accept an answer involving sed (or awk, or any other similar method) instead of just using the utilities installed with the OS is beyond me.
â Auspex
Feb 28 at 11:48
@Auspex I'd guess it's simply becausedirname
andbasename
are not widely known, butsed
andawk
are.
â Volker Siegel
Feb 28 at 13:08
add a comment |Â
2
Honestly, why anyone would either suggest or accept an answer involving sed (or awk, or any other similar method) instead of just using the utilities installed with the OS is beyond me.
â Auspex
Feb 28 at 11:48
@Auspex I'd guess it's simply becausedirname
andbasename
are not widely known, butsed
andawk
are.
â Volker Siegel
Feb 28 at 13:08
2
2
Honestly, why anyone would either suggest or accept an answer involving sed (or awk, or any other similar method) instead of just using the utilities installed with the OS is beyond me.
â Auspex
Feb 28 at 11:48
Honestly, why anyone would either suggest or accept an answer involving sed (or awk, or any other similar method) instead of just using the utilities installed with the OS is beyond me.
â Auspex
Feb 28 at 11:48
@Auspex I'd guess it's simply because
dirname
and basename
are not widely known, but sed
and awk
are.â Volker Siegel
Feb 28 at 13:08
@Auspex I'd guess it's simply because
dirname
and basename
are not widely known, but sed
and awk
are.â Volker Siegel
Feb 28 at 13:08
add a comment |Â
up vote
15
down vote
Parameter expansion in bash
You can use parameter expansion in bash
, in this case
$parameter%word
whereword
is/*
$parameter##word
whereword
is*/
Examples:
Remove the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf%/*
xxx/xxxx/xxxxx
This is described in man bash
:
$parameter%word
$parameter%%word
Remove matching suffix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with
the shortest matching pattern (the ``%'' case) or the longest
matching pattern (the ``%%'' case) deleted. If parameter is @
or *, the pattern removal operation is applied to each posiâÂÂ
tional parameter in turn, and the expansion is the resultant
list. If parameter is an array variable subscripted with @ or
*, the pattern removal operation is applied to each member of
the array in turn, and the expansion is the resultant list.
Remove all except the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf##*/
yyy
You can add a slash like so
$ echo /$asdf##*/
/yyy
to get exactly what you wanted at one particular instance according to the edited question. But the question has been edited by several people after that and it is not easy to know what you want now.
This is described in man bash
:
$parameter#word
$parameter##word
Remove matching prefix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
the beginning of the value of parameter, then the result of the
expansion is the expanded value of parameter with the shortest
matching pattern (the ``#'' case) or the longest matching patâÂÂ
tern (the ``##'' case) deleted. If parameter is @ or *, the
pattern removal operation is applied to each positional parameâÂÂ
ter in turn, and the expansion is the resultant list. If paramâÂÂ
eter is an array variable subscripted with @ or *, the pattern
removal operation is applied to each member of the array in
turn, and the expansion is the resultant list.
add a comment |Â
up vote
15
down vote
Parameter expansion in bash
You can use parameter expansion in bash
, in this case
$parameter%word
whereword
is/*
$parameter##word
whereword
is*/
Examples:
Remove the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf%/*
xxx/xxxx/xxxxx
This is described in man bash
:
$parameter%word
$parameter%%word
Remove matching suffix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with
the shortest matching pattern (the ``%'' case) or the longest
matching pattern (the ``%%'' case) deleted. If parameter is @
or *, the pattern removal operation is applied to each posiâÂÂ
tional parameter in turn, and the expansion is the resultant
list. If parameter is an array variable subscripted with @ or
*, the pattern removal operation is applied to each member of
the array in turn, and the expansion is the resultant list.
Remove all except the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf##*/
yyy
You can add a slash like so
$ echo /$asdf##*/
/yyy
to get exactly what you wanted at one particular instance according to the edited question. But the question has been edited by several people after that and it is not easy to know what you want now.
This is described in man bash
:
$parameter#word
$parameter##word
Remove matching prefix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
the beginning of the value of parameter, then the result of the
expansion is the expanded value of parameter with the shortest
matching pattern (the ``#'' case) or the longest matching patâÂÂ
tern (the ``##'' case) deleted. If parameter is @ or *, the
pattern removal operation is applied to each positional parameâÂÂ
ter in turn, and the expansion is the resultant list. If paramâÂÂ
eter is an array variable subscripted with @ or *, the pattern
removal operation is applied to each member of the array in
turn, and the expansion is the resultant list.
add a comment |Â
up vote
15
down vote
up vote
15
down vote
Parameter expansion in bash
You can use parameter expansion in bash
, in this case
$parameter%word
whereword
is/*
$parameter##word
whereword
is*/
Examples:
Remove the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf%/*
xxx/xxxx/xxxxx
This is described in man bash
:
$parameter%word
$parameter%%word
Remove matching suffix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with
the shortest matching pattern (the ``%'' case) or the longest
matching pattern (the ``%%'' case) deleted. If parameter is @
or *, the pattern removal operation is applied to each posiâÂÂ
tional parameter in turn, and the expansion is the resultant
list. If parameter is an array variable subscripted with @ or
*, the pattern removal operation is applied to each member of
the array in turn, and the expansion is the resultant list.
Remove all except the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf##*/
yyy
You can add a slash like so
$ echo /$asdf##*/
/yyy
to get exactly what you wanted at one particular instance according to the edited question. But the question has been edited by several people after that and it is not easy to know what you want now.
This is described in man bash
:
$parameter#word
$parameter##word
Remove matching prefix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
the beginning of the value of parameter, then the result of the
expansion is the expanded value of parameter with the shortest
matching pattern (the ``#'' case) or the longest matching patâÂÂ
tern (the ``##'' case) deleted. If parameter is @ or *, the
pattern removal operation is applied to each positional parameâÂÂ
ter in turn, and the expansion is the resultant list. If paramâÂÂ
eter is an array variable subscripted with @ or *, the pattern
removal operation is applied to each member of the array in
turn, and the expansion is the resultant list.
Parameter expansion in bash
You can use parameter expansion in bash
, in this case
$parameter%word
whereword
is/*
$parameter##word
whereword
is*/
Examples:
Remove the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf%/*
xxx/xxxx/xxxxx
This is described in man bash
:
$parameter%word
$parameter%%word
Remove matching suffix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with
the shortest matching pattern (the ``%'' case) or the longest
matching pattern (the ``%%'' case) deleted. If parameter is @
or *, the pattern removal operation is applied to each posiâÂÂ
tional parameter in turn, and the expansion is the resultant
list. If parameter is an array variable subscripted with @ or
*, the pattern removal operation is applied to each member of
the array in turn, and the expansion is the resultant list.
Remove all except the last part
$ asdf="xxx/xxxx/xxxxx/yyy"
$ echo $asdf##*/
yyy
You can add a slash like so
$ echo /$asdf##*/
/yyy
to get exactly what you wanted at one particular instance according to the edited question. But the question has been edited by several people after that and it is not easy to know what you want now.
This is described in man bash
:
$parameter#word
$parameter##word
Remove matching prefix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
the beginning of the value of parameter, then the result of the
expansion is the expanded value of parameter with the shortest
matching pattern (the ``#'' case) or the longest matching patâÂÂ
tern (the ``##'' case) deleted. If parameter is @ or *, the
pattern removal operation is applied to each positional parameâÂÂ
ter in turn, and the expansion is the resultant list. If paramâÂÂ
eter is an array variable subscripted with @ or *, the pattern
removal operation is applied to each member of the array in
turn, and the expansion is the resultant list.
edited Feb 28 at 19:28
answered Feb 27 at 15:33
![](https://i.stack.imgur.com/lcww5.png?s=32&g=1)
![](https://i.stack.imgur.com/lcww5.png?s=32&g=1)
sudodus
20.4k32668
20.4k32668
add a comment |Â
add a comment |Â
up vote
9
down vote
Another way is to use grep
to only display the last slash per line and whatever follows it:
$ grep -o '/[^/]*$' example.txt
/yyy
/yyyyy
Explanation:
-o
tells grep
to only show the matching part of the line instead of the whole line.
The pattern /[^/]*$
matches a literal slash /
followed by any character except for a slash [^/]
any number of times *
until the end of the line $
.
add a comment |Â
up vote
9
down vote
Another way is to use grep
to only display the last slash per line and whatever follows it:
$ grep -o '/[^/]*$' example.txt
/yyy
/yyyyy
Explanation:
-o
tells grep
to only show the matching part of the line instead of the whole line.
The pattern /[^/]*$
matches a literal slash /
followed by any character except for a slash [^/]
any number of times *
until the end of the line $
.
add a comment |Â
up vote
9
down vote
up vote
9
down vote
Another way is to use grep
to only display the last slash per line and whatever follows it:
$ grep -o '/[^/]*$' example.txt
/yyy
/yyyyy
Explanation:
-o
tells grep
to only show the matching part of the line instead of the whole line.
The pattern /[^/]*$
matches a literal slash /
followed by any character except for a slash [^/]
any number of times *
until the end of the line $
.
Another way is to use grep
to only display the last slash per line and whatever follows it:
$ grep -o '/[^/]*$' example.txt
/yyy
/yyyyy
Explanation:
-o
tells grep
to only show the matching part of the line instead of the whole line.
The pattern /[^/]*$
matches a literal slash /
followed by any character except for a slash [^/]
any number of times *
until the end of the line $
.
answered Feb 27 at 15:37
![](https://i.stack.imgur.com/m8DYH.jpg?s=32&g=1)
![](https://i.stack.imgur.com/m8DYH.jpg?s=32&g=1)
Byte Commander
59.7k26159268
59.7k26159268
add a comment |Â
add a comment |Â
up vote
7
down vote
Just because others have posted more âÂÂsaneâ answers, hereâÂÂs a somewhat silly one:
rev | cut -d/ -f1 | rev
rev
reverses the characters in each line, e.g. abcd/ef/g
becomes g/fe/dcba
. Then cut
cuts out the first segment. Finally itâÂÂs reversed again.
1
Despite the non-sanity of this answer, especially because of the shell plumbing, I like this answer :) Keep on rocking, +1
â Sergiy Kolodyazhnyy
Feb 28 at 2:32
Agreed - not sane, but badass!
â Volker Siegel
Feb 28 at 12:12
add a comment |Â
up vote
7
down vote
Just because others have posted more âÂÂsaneâ answers, hereâÂÂs a somewhat silly one:
rev | cut -d/ -f1 | rev
rev
reverses the characters in each line, e.g. abcd/ef/g
becomes g/fe/dcba
. Then cut
cuts out the first segment. Finally itâÂÂs reversed again.
1
Despite the non-sanity of this answer, especially because of the shell plumbing, I like this answer :) Keep on rocking, +1
â Sergiy Kolodyazhnyy
Feb 28 at 2:32
Agreed - not sane, but badass!
â Volker Siegel
Feb 28 at 12:12
add a comment |Â
up vote
7
down vote
up vote
7
down vote
Just because others have posted more âÂÂsaneâ answers, hereâÂÂs a somewhat silly one:
rev | cut -d/ -f1 | rev
rev
reverses the characters in each line, e.g. abcd/ef/g
becomes g/fe/dcba
. Then cut
cuts out the first segment. Finally itâÂÂs reversed again.
Just because others have posted more âÂÂsaneâ answers, hereâÂÂs a somewhat silly one:
rev | cut -d/ -f1 | rev
rev
reverses the characters in each line, e.g. abcd/ef/g
becomes g/fe/dcba
. Then cut
cuts out the first segment. Finally itâÂÂs reversed again.
answered Feb 27 at 16:55
egmont
3,5691821
3,5691821
1
Despite the non-sanity of this answer, especially because of the shell plumbing, I like this answer :) Keep on rocking, +1
â Sergiy Kolodyazhnyy
Feb 28 at 2:32
Agreed - not sane, but badass!
â Volker Siegel
Feb 28 at 12:12
add a comment |Â
1
Despite the non-sanity of this answer, especially because of the shell plumbing, I like this answer :) Keep on rocking, +1
â Sergiy Kolodyazhnyy
Feb 28 at 2:32
Agreed - not sane, but badass!
â Volker Siegel
Feb 28 at 12:12
1
1
Despite the non-sanity of this answer, especially because of the shell plumbing, I like this answer :) Keep on rocking, +1
â Sergiy Kolodyazhnyy
Feb 28 at 2:32
Despite the non-sanity of this answer, especially because of the shell plumbing, I like this answer :) Keep on rocking, +1
â Sergiy Kolodyazhnyy
Feb 28 at 2:32
Agreed - not sane, but badass!
â Volker Siegel
Feb 28 at 12:12
Agreed - not sane, but badass!
â Volker Siegel
Feb 28 at 12:12
add a comment |Â
up vote
3
down vote
Classic solution with awk
, that treats /
as field separator for both input and output and sets the last field to empty string ( which really is "dereferencing" of the number of fields NF
variable ):
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";$NF="";print $0'
xxx/xxxx/xxxxx/
Shorter, as fedorqui pointed out in the comments:
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";NF--'
xxx/xxxx/xxxxx/
Variation on that would be to put path into awk
's execution environment, which will save up on plumbing but makes awk
portion more verbose:
mypath="xxx/xxxx/xxxxx/yyy" awk 'BEGINOFS=FS="/"; sub(//([^/]*)$/,"",ENVIRON["mypath"]);print(ENVIRON["mypath"]) ;'
1
Too verbose, why not justNF--
? This way you avoud theprint
bla bla.
â fedorqui
Feb 28 at 9:35
add a comment |Â
up vote
3
down vote
Classic solution with awk
, that treats /
as field separator for both input and output and sets the last field to empty string ( which really is "dereferencing" of the number of fields NF
variable ):
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";$NF="";print $0'
xxx/xxxx/xxxxx/
Shorter, as fedorqui pointed out in the comments:
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";NF--'
xxx/xxxx/xxxxx/
Variation on that would be to put path into awk
's execution environment, which will save up on plumbing but makes awk
portion more verbose:
mypath="xxx/xxxx/xxxxx/yyy" awk 'BEGINOFS=FS="/"; sub(//([^/]*)$/,"",ENVIRON["mypath"]);print(ENVIRON["mypath"]) ;'
1
Too verbose, why not justNF--
? This way you avoud theprint
bla bla.
â fedorqui
Feb 28 at 9:35
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Classic solution with awk
, that treats /
as field separator for both input and output and sets the last field to empty string ( which really is "dereferencing" of the number of fields NF
variable ):
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";$NF="";print $0'
xxx/xxxx/xxxxx/
Shorter, as fedorqui pointed out in the comments:
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";NF--'
xxx/xxxx/xxxxx/
Variation on that would be to put path into awk
's execution environment, which will save up on plumbing but makes awk
portion more verbose:
mypath="xxx/xxxx/xxxxx/yyy" awk 'BEGINOFS=FS="/"; sub(//([^/]*)$/,"",ENVIRON["mypath"]);print(ENVIRON["mypath"]) ;'
Classic solution with awk
, that treats /
as field separator for both input and output and sets the last field to empty string ( which really is "dereferencing" of the number of fields NF
variable ):
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";$NF="";print $0'
xxx/xxxx/xxxxx/
Shorter, as fedorqui pointed out in the comments:
$ echo "xxx/xxxx/xxxxx/yyy"|awk 'BEGINOFS=FS="/";NF--'
xxx/xxxx/xxxxx/
Variation on that would be to put path into awk
's execution environment, which will save up on plumbing but makes awk
portion more verbose:
mypath="xxx/xxxx/xxxxx/yyy" awk 'BEGINOFS=FS="/"; sub(//([^/]*)$/,"",ENVIRON["mypath"]);print(ENVIRON["mypath"]) ;'
edited Feb 28 at 9:54
answered Feb 28 at 2:43
![](https://i.stack.imgur.com/U1Jy6.jpg?s=32&g=1)
![](https://i.stack.imgur.com/U1Jy6.jpg?s=32&g=1)
Sergiy Kolodyazhnyy
65.7k9134287
65.7k9134287
1
Too verbose, why not justNF--
? This way you avoud theprint
bla bla.
â fedorqui
Feb 28 at 9:35
add a comment |Â
1
Too verbose, why not justNF--
? This way you avoud theprint
bla bla.
â fedorqui
Feb 28 at 9:35
1
1
Too verbose, why not just
NF--
? This way you avoud the print
bla bla.â fedorqui
Feb 28 at 9:35
Too verbose, why not just
NF--
? This way you avoud the print
bla bla.â fedorqui
Feb 28 at 9:35
add a comment |Â
up vote
2
down vote
Adding to egmont's answer because the question has been edited...
Use --complement if you want to remove the first field with -f1.
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1 --complement|rev
xxxx/x/xx/xx/xxxx/x
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1|rev
yyyyy
Also, the question isn't quite clear about what should happen with inputs not containing any slashes.
xxxx => xxxx
or
xxxx => nothing
You can suggest an edit to it: askubuntu.com/posts/1010356/edit
â muru
Feb 28 at 14:08
@muru OP is 1 rep user. Isn't editing privilege is granted at 2k ? askubuntu.com/help/privileges/edit
â Sergiy Kolodyazhnyy
Feb 28 at 18:47
@SergiyKolodyazhnyy anybody can suggest edits.
â muru
Feb 28 at 21:26
+1 - I had not noticed the--complement
option before and the man page is circular. Complement means complement. I found a nice cut tutorial which covers it at yourownlinux.com/2015/05/⦠It's like-v
ingrep
. Give me everything except what was matched.
â Joe
Feb 28 at 23:59
1
-f2-
is a simpler form for-f1 --complement
.
â egmont
Mar 1 at 0:04
add a comment |Â
up vote
2
down vote
Adding to egmont's answer because the question has been edited...
Use --complement if you want to remove the first field with -f1.
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1 --complement|rev
xxxx/x/xx/xx/xxxx/x
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1|rev
yyyyy
Also, the question isn't quite clear about what should happen with inputs not containing any slashes.
xxxx => xxxx
or
xxxx => nothing
You can suggest an edit to it: askubuntu.com/posts/1010356/edit
â muru
Feb 28 at 14:08
@muru OP is 1 rep user. Isn't editing privilege is granted at 2k ? askubuntu.com/help/privileges/edit
â Sergiy Kolodyazhnyy
Feb 28 at 18:47
@SergiyKolodyazhnyy anybody can suggest edits.
â muru
Feb 28 at 21:26
+1 - I had not noticed the--complement
option before and the man page is circular. Complement means complement. I found a nice cut tutorial which covers it at yourownlinux.com/2015/05/⦠It's like-v
ingrep
. Give me everything except what was matched.
â Joe
Feb 28 at 23:59
1
-f2-
is a simpler form for-f1 --complement
.
â egmont
Mar 1 at 0:04
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Adding to egmont's answer because the question has been edited...
Use --complement if you want to remove the first field with -f1.
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1 --complement|rev
xxxx/x/xx/xx/xxxx/x
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1|rev
yyyyy
Also, the question isn't quite clear about what should happen with inputs not containing any slashes.
xxxx => xxxx
or
xxxx => nothing
Adding to egmont's answer because the question has been edited...
Use --complement if you want to remove the first field with -f1.
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1 --complement|rev
xxxx/x/xx/xx/xxxx/x
echo "xxxx/x/xx/xx/xxxx/x/yyyyy"|rev|cut -d/ -f1|rev
yyyyy
Also, the question isn't quite clear about what should happen with inputs not containing any slashes.
xxxx => xxxx
or
xxxx => nothing
edited Feb 28 at 14:09
answered Feb 28 at 14:07
Ph3n0x
212
212
You can suggest an edit to it: askubuntu.com/posts/1010356/edit
â muru
Feb 28 at 14:08
@muru OP is 1 rep user. Isn't editing privilege is granted at 2k ? askubuntu.com/help/privileges/edit
â Sergiy Kolodyazhnyy
Feb 28 at 18:47
@SergiyKolodyazhnyy anybody can suggest edits.
â muru
Feb 28 at 21:26
+1 - I had not noticed the--complement
option before and the man page is circular. Complement means complement. I found a nice cut tutorial which covers it at yourownlinux.com/2015/05/⦠It's like-v
ingrep
. Give me everything except what was matched.
â Joe
Feb 28 at 23:59
1
-f2-
is a simpler form for-f1 --complement
.
â egmont
Mar 1 at 0:04
add a comment |Â
You can suggest an edit to it: askubuntu.com/posts/1010356/edit
â muru
Feb 28 at 14:08
@muru OP is 1 rep user. Isn't editing privilege is granted at 2k ? askubuntu.com/help/privileges/edit
â Sergiy Kolodyazhnyy
Feb 28 at 18:47
@SergiyKolodyazhnyy anybody can suggest edits.
â muru
Feb 28 at 21:26
+1 - I had not noticed the--complement
option before and the man page is circular. Complement means complement. I found a nice cut tutorial which covers it at yourownlinux.com/2015/05/⦠It's like-v
ingrep
. Give me everything except what was matched.
â Joe
Feb 28 at 23:59
1
-f2-
is a simpler form for-f1 --complement
.
â egmont
Mar 1 at 0:04
You can suggest an edit to it: askubuntu.com/posts/1010356/edit
â muru
Feb 28 at 14:08
You can suggest an edit to it: askubuntu.com/posts/1010356/edit
â muru
Feb 28 at 14:08
@muru OP is 1 rep user. Isn't editing privilege is granted at 2k ? askubuntu.com/help/privileges/edit
â Sergiy Kolodyazhnyy
Feb 28 at 18:47
@muru OP is 1 rep user. Isn't editing privilege is granted at 2k ? askubuntu.com/help/privileges/edit
â Sergiy Kolodyazhnyy
Feb 28 at 18:47
@SergiyKolodyazhnyy anybody can suggest edits.
â muru
Feb 28 at 21:26
@SergiyKolodyazhnyy anybody can suggest edits.
â muru
Feb 28 at 21:26
+1 - I had not noticed the
--complement
option before and the man page is circular. Complement means complement. I found a nice cut tutorial which covers it at yourownlinux.com/2015/05/⦠It's like -v
in grep
. Give me everything except what was matched.â Joe
Feb 28 at 23:59
+1 - I had not noticed the
--complement
option before and the man page is circular. Complement means complement. I found a nice cut tutorial which covers it at yourownlinux.com/2015/05/⦠It's like -v
in grep
. Give me everything except what was matched.â Joe
Feb 28 at 23:59
1
1
-f2-
is a simpler form for -f1 --complement
.â egmont
Mar 1 at 0:04
-f2-
is a simpler form for -f1 --complement
.â egmont
Mar 1 at 0:04
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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%2faskubuntu.com%2fquestions%2f1010310%2fcutting-all-the-characters-after-the-last%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
4
Are you trying to omit or isolate the characters after the last
/
?â dsstorefile1
Feb 27 at 15:34
Good question, I just realised that we didn't understand the question the same way
â Félicien
Feb 27 at 15:35
3
The commands
basename
anddirname
do this already.â Michael Hampton
Feb 28 at 0:49
I don't think edit #5 to the question was correct. Using the word "cut" might be ambiguous; if you cut something, do you throw away that part, or do you keep only that? However, the previous wording "and to omit what is before the /" was unambiguous. This was changed to its opposite.
â egmont
Mar 1 at 0:02
@egmont the word "cut" itself was carried over from the original: "I need to cut only the charachters after the last
/
" became "How do I cut all characters after the last '/'?" which is a change of phrasing that reasonably keeps the meaning, IMO. If anything, I felt the "omit what is ..." part ambiguous: the examples seem to keep what is before the/
. The example, makes it clear, anyway.â muru
Mar 1 at 4:30