tags:

views:

38

answers:

3

I need to get the name 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
+1  A: 

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.

Alok
+1  A: 

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

Moron
+1  A: 

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%.*}
ghostdog74
Since the OP wanted the extension removed: `file=${var##*/}; base=${file%.*}`
Dennis Williamson
yes. I missed that. thanks
ghostdog74