Deleting a word from a string

Hello All,
I have a string like below -

 /LDCA20/rel/prod/libina.a
               I want to delete "libina.a" which is at the end.How can I do this ?? 

                Thanks in advance

Regards,
Anand

Is it in a file? A variable? What system are you on? What shell?

In ksh93/bash:

a=' /LDCA20/rel/prod/libina.a'

echo "$a"
 /LDCA20/rel/prod/libina.a

a=${a/%libina.a/}

echo "$a"
 /LDCA20/rel/prod/

Hello I want to use a

sed

command.B'coz I am getting input piped from some other command . Can you suggest me a way to use

sed 

command

echo ' /LDCA20/rel/prod/libina.a'|sed '/libina\.a$/s///'
 /LDCA20/rel/prod/
1 Like

@elixir_sinari
Can you explain this one

Thank you very much.I got it now.

Don't get confused by the empty pattern and replacement fields :).
After the match is successful ( /libina\.a$/ ), the first // will correspond to the last pattern matched. That is, it is corresponding to the same pattern /libina\.a$/ . And I hope you know what the blank replacement string is for.
The command is equivalent to:

echo ' /LDCA20/rel/prod/libina.a'|sed '/libina\.a$/s/libina\.a$//'

Slight modifications (in any POSIX compliant shell, not just bash/ksh93)):

echo "${a%libina.a}"
sed 's/libina\.a$//'

@elixir_sinari,,Thanks GOOD explanation..

If it's the filename you always want to remove, you can just use this:

$ dirname ' /LDCA20/rel/prod/libina.a'
 /LDCA20/rel/prod