1

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

3 Answers 3

2

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%.*}
Sign up to request clarification or add additional context in comments.

1 Comment

Since the OP wanted the extension removed: file=${var##*/}; base=${file%.*}
1

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.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.