Here you go:
My input file "a" contains:
my-do-not-change-airplane and other frogs
airplane.seriously change me
sometimes in the file i'm using,
there are words like this: db-airplane, db-12.airplane.
in cases like that, your code turns
the words into db-helicopter, db-12.helicopter.
airplane,frogs,somewerirdairplane buggly buggly
aardvark,chameleon,airplane,dugong,basilisk
aardvark,chameleon,dugong,basilisk,airplane
My script, "clam" looks like this:
#!/bin/ksh
#----------------------------------------------------------------------#
# Find funky occurances of airplane... #
#----------------------------------------------------------------------#
cat a |
#----------------------------------------------------------------------#
# Translate any and word delimiters to newlines... #
#----------------------------------------------------------------------#
tr '[. , ]' '\012\012\012\012' |
grep airplane |
#----------------------------------------------------------------------#
# Grep OUT our target word to change... #
#----------------------------------------------------------------------#
grep -v "^airplane$" |
sort -u |
while read pattern ; do
#----------------------------------------------------------------------#
# Create list of sed commands... #
#----------------------------------------------------------------------#
print "s/$pattern/${pattern}DONOTEDIT/g;"
done > sed.file
#----------------------------------------------------------------------#
# Finish our little sed script. Remove our DONOTEDIT strings. #
#----------------------------------------------------------------------#
cat << EOF >> sed.file
s/\<airplane\>/HELICOPTER/g;
s/DONOTEDIT//g;
EOF
#----------------------------------------------------------------------#
# ... and voila.... #
#----------------------------------------------------------------------#
sed -f sed.file a
... and the output is:
my-do-not-change-airplane and other frogs
HELICOPTER.seriously change me
sometimes in the file i'm using,
there are words like this: db-airplane, db-12.HELICOPTER.
in cases like that, your code turns
the words into db-helicopter, db-12.helicopter.
HELICOPTER,frogs,somewerirdairplane buggly buggly
aardvark,chameleon,HELICOPTER,dugong,basilisk
aardvark,chameleon,dugong,basilisk,HELICOPTER