rdhanek
September 11, 2009, 2:44am
1
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
Shazin
September 11, 2009, 2:55am
3
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
rdhanek
September 11, 2009, 3:40am
5
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??
clx
September 11, 2009, 4:52am
7
something like:
sed -e "s/[a-zA-Z-][a-zA-Z-]*XYZ[' ]*//g" -e "s/XYZ[a-zA-Z-][a-zA-Z-]*//g" filename
poldo
September 11, 2009, 5:32am
8
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