shell script to get the file name from a string
I need to get the basnename of the file (esrt-deghasdf-keystore) before .jks. I want to do it using开发者_运维问答 shellscript. Is it possible?
abcdefgh 7369 4825 0 00:12:26 pts/10 0:37 java -Djavax.net.ssl.keyStore=/abc3/esrt/der/fer-def2/esrt-deghasdf-keystore.jks
no need external tools. ksh can do the job
$ var="abcdefgh 7369 4825 0 00:12:26 pts/10 0:37 java -Djavax.net.ssl.keyStore=/abc3/esrt/der/fer-def2/esrt-deghasdf-keystore.jks"
$ echo ${var##*/}
esrt-deghasdf-keystore.jks
$ var=${var##*/}
$ echo ${var%.*}
It depends upon the format of the line. If you lines are all going to end in /path/to/file.ext
format, you can do:
echo $line | sed -e 's@.*/@@g' -e 's@\.[^.]*$@@g'
but really, it depends upon how exactly your lines are formatted and what you want out of it.
Use cut piped to sed. (some thing like cut -f 7 | sed blah)
Sorry I don't remember exactly how to use both.
See the manpages: cut and sed
精彩评论