How can i delete a keyword containing XYZ in unix

Hi all,

I am trying to remove the words which has XYZ as a prt of that.

My input file is something like this :

PHNDAZLF-UPS-XYZ' aaaaaaa bbbbb
ADFRTEJKS-XYZ cccccccc ddddddd rrrrrr
SGETHEHDJ-ABC-RXY' hhhhh ttttt' kkkk
FHJSKSJDKD-XXX-YYY

Output expected is :

aaaaaaa bbbbb
cccccccc ddddddd rrrrrr
SGETHEHDJ-ABC-RXY' hhhhh ttttt' kkkk
FHJSKSJDKD-XXX-YYY

Have you tried grep? Have a read of the man page.

Regards

Hi,

You can use the below code:

grep xyz filename > temp_filename
if [ $? -eq 0 ] ; then
echo "Pattern exist in filename"
sed "/$value/d" filename > temp_filename
mv temp_filename filename
echo "Pattern deleted"
else
echo "Pattern does not exist in filename"
fi

Cheers,
Shazin

Simply do this:
grep -v XYZ > file_without_XYZ

I apologize for the confusion. But i want to delete the words having XYZ as a part of them and not the total lines.

I have also modified the example above now.
Not sure if this is still possible with grep??

Its simple using sed

sed 's/xyz//' FILENAME

something like:

sed -e "s/[a-zA-Z-][a-zA-Z-]*XYZ[' ]*//g" -e "s/XYZ[a-zA-Z-][a-zA-Z-]*//g" filename

hi, maybe you could try this.

sed 's/.*XYZ*. //g' file_name

---------- Post updated at 05:32 PM ---------- Previous update was at 05:14 PM ----------

maybe you could try this, not sure if this is what you need.

sed "s/[A-Z-]*XYZ*[A-Z-][ ']//g" filename