Deleting a word from a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting a word from a string
# 1  
Old 10-11-2012
Deleting a word from a string

Hello All,
I have a string like below -
Code:
 /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
# 2  
Old 10-11-2012
Is it in a file? A variable? What system are you on? What shell?
# 3  
Old 10-11-2012
In ksh93/bash:
Code:
a=' /LDCA20/rel/prod/libina.a'

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

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

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


Last edited by elixir_sinari; 10-11-2012 at 07:35 AM..
# 4  
Old 10-11-2012
Hello I want to use a
Code:
sed

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

command
# 5  
Old 10-11-2012
Code:
echo ' /LDCA20/rel/prod/libina.a'|sed '/libina\.a$/s///'
 /LDCA20/rel/prod/

This User Gave Thanks to elixir_sinari For This Post:
# 6  
Old 10-11-2012
@elixir_sinari
Can you explain this one
# 7  
Old 10-11-2012
Thank you very much.I got it now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed for deleting the first word of each line?

sed /'1-2'/&^/ filename suppose there is a file containing three lines , how do we do delete the word from each line? hyter efr frf rerfer efe ewd cdcf evrfgf erfv the output has to look like frf ewd erfv (2 Replies)
Discussion started by: Rajeev Nukala
2 Replies

2. Shell Programming and Scripting

Deleting lines in a fixed length file where there is a word at specific location

I have a big file having 100 K lines. I have to read each line and see at 356 character position whethere there is a word "W" in it. If it is their then don't delete the line otherwise delete it. There are two lines as one Header and one trailer which should remain same. Can somebody... (5 Replies)
Discussion started by: mohit kanoongo
5 Replies

3. Shell Programming and Scripting

Deleting rows starting with a character and word

Hi, I have multiple files of same format and I want to delete the lines starting with # and The from all of them I am using egrep -v '^(#|$)' for # but unable to do for both # and The Please guide Thanks (12 Replies)
Discussion started by: bioinfo
12 Replies

4. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

5. Shell Programming and Scripting

Replace a word in a string starting with another word

Hi All, I have a file in which a number of lines are starting with similar first word but different next words. I want to replace the any nth word(not 1st or 2nd) with another word. Eg:- My file contains are like this:- Ram is a boy. Ram is a good boy. Ram plays cricket. Here I want to... (2 Replies)
Discussion started by: mukeshbaranwal
2 Replies

6. Shell Programming and Scripting

grep part of word or Another word from a string

Hi all, FileOne family balance >>>>> 0 0 0 0 java.io.FileNotFoundException: Settings.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) .. .... ..... ..... java.lang.NullPointerException ... ..... ...... Stacktrace: at... (2 Replies)
Discussion started by: linuxadmin
2 Replies

7. Shell Programming and Scripting

sed - deleting each line up to a word

Hi there, I'd like to delete the beginning of a line up until it finds a certain word or character string: in this case, I'd like to delete each line up to the word "mounting". Thanks ;) Susan (12 Replies)
Discussion started by: kitykity
12 Replies

8. Shell Programming and Scripting

deleting lines above and below a word!

i jst want to delete a host entry from httpd.conf for eg: i have entries such as: <VirtualHost 192.168.1.157:80> DocumentRoot /home/karthik ServerName kar </VirtualHost> <VirtualHost 192.168.1.157:80> DocumentRoot /home/karthik1 ServerName www </VirtualHost> <VirtualHost... (4 Replies)
Discussion started by: jacky29
4 Replies

9. UNIX for Dummies Questions & Answers

deleting word from this point to end of file in VI

Hi All i need to delete a recurring word from point "n" till end of the file. there are other words in this file so i cannot use `dG`, can anyone help me out? Kind regards Brian (4 Replies)
Discussion started by: brian112
4 Replies

10. Shell Programming and Scripting

deleting last characters of a word

Hi All is there a way to delete last n characters from a word like say i have employee_new i want to delete _new. and just get only employee I want this in AIX Shell scripting Thanks (3 Replies)
Discussion started by: rajaryan4545
3 Replies
Login or Register to Ask a Question