If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > word deleting in a file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-03, 09:52
sunragh sunragh is offline
Registered User
 
Join Date: Apr 2003
Posts: 5
word deleting in a file

dear all,
a particular word which occures at many places in a large file is to be deleted.
Pl help.
TIA
sunil
Reply With Quote
  #2 (permalink)  
Old 04-17-03, 17:17
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
Re: word deleting in a file

cat filename | sed 's/word//g' > newfile

Cheers

Sathyaram

Quote:
Originally posted by sunragh
dear all,
a particular word which occures at many places in a large file is to be deleted.
Pl help.
TIA
sunil
Reply With Quote
  #3 (permalink)  
Old 04-18-03, 00:23
sunragh sunragh is offline
Registered User
 
Join Date: Apr 2003
Posts: 5
Thanks a lot, it worked.
Reply With Quote
  #4 (permalink)  
Old 04-20-03, 19:49
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
Re: word deleting in a file

Sorry, the script will delete all occurences of the word, even if it is a part of another word ... to delete only the word, you can do

cat filename | sed 's/ word /g;s/ word././g'

If you have any other format the word will occur, include them also in the above script ...

There could be other ways also ...

cheers

Sathyaram

Quote:
Originally posted by sathyaram_s
cat filename | sed 's/word//g' > newfile

Cheers

Sathyaram
Reply With Quote
  #5 (permalink)  
Old 04-21-03, 01:47
sunragh sunragh is offline
Registered User
 
Join Date: Apr 2003
Posts: 5
Re: word deleting in a file

i have a file by name test, which contains words like raju, raju12, raju123.
when i run this command

# cat test |sed 's/raju/g;s/raju././g' >test1

the output is
sed: command garbled: s/raju/g;s/raju././g

I am using solaris-8.





Quote:
Originally posted by sathyaram_s
Sorry, the script will delete all occurences of the word, even if it is a part of another word ... to delete only the word, you can do

cat filename | sed 's/ word /g;s/ word././g'

If you have any other format the word will occur, include them also in the above script ...

There could be other ways also ...

cheers

Sathyaram
Reply With Quote
  #6 (permalink)  
Old 04-21-03, 06:56
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
Re: word deleting in a file

Sorry, I missed a '/' ...

It should have been


cat filename | sed 's/ word / /g;s/ word././g'

In the command :

s/word1/word2/g

s - means search for a string
word1 - is the search string
word2 - is the replace with string
g - indicates, do replacement of word1 with word2 globally

A semi-colon( is used to a separator between two command within sed ...

HTH

Sathyaram


Quote:
Originally posted by sunragh
i have a file by name test, which contains words like raju, raju12, raju123.
when i run this command

# cat test |sed 's/raju/g;s/raju././g' >test1

the output is
sed: command garbled: s/raju/g;s/raju././g

I am using solaris-8.
Reply With Quote
  #7 (permalink)  
Old 04-21-03, 07:21
sunragh sunragh is offline
Registered User
 
Join Date: Apr 2003
Posts: 5
Re: word deleting in a file

Dear sir,
I have the following file.
#cat file
one farmer had
four sons
their names are
raju
raju1
raju2
raju3
raju was a good boy.
rest of raju were even good.
#
Now my requirement is only the word raju is tobe deleted from this file
Pl help
regards
sunil
Reply With Quote
  #8 (permalink)  
Old 05-01-03, 15:02
lelle12 lelle12 is offline
Registered User
 
Join Date: Mar 2003
Posts: 86
the following remove any lines with zero or more spaces followed by raju followed by zero or more spaces

sed -e "s/^[ ]*raju[ ]*$//g"

if you want to get rid of the empty lines it leaves:

sed -e "s/^[ ]*raju[ ]*$//g" -e "/^$/d"


HTH
/Lennart
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On