PDA

View Full Version : word deleting in a file


sunragh
04-17-03, 10:52
dear all,
a particular word which occures at many places in a large file is to be deleted.
Pl help.
TIA
sunil

sathyaram_s
04-17-03, 18:17
cat filename | sed 's/word//g' > newfile

Cheers

Sathyaram

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

sunragh
04-18-03, 01:23
Thanks a lot, it worked.

sathyaram_s
04-20-03, 20:49
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

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

Cheers

Sathyaram

sunragh
04-21-03, 02:47
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.





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

sathyaram_s
04-21-03, 07:56
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


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.

sunragh
04-21-03, 08:21
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

lelle12
05-01-03, 16:02
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