jvsaha
asked on
bash script that replaces string in files to be used in cygwin
I just installed cygwin on my windows XP. I want to write a bash script to find this "<!--<~~" string in all the jsp files and replace it with "<%" string. Below is my attempt on the bash script and the errors I got. Note, it even complains about the mv command. Can anyone help me? If you have the solution, please give me some explanation as well since I am new to shell programming. Thanks.
#!/bin/bash
# Filename: srTags.sh
# Find all jsp file
# Search for <!--<~~ tag and replace with <% tag in all jsp files found
# Search for ~~>--> tag and replace with %> tag
OLDTAG1="<!--<~~"
NEWTAG1="<%"
OLDTAG2="~~>-->"
NEWTAG2="%>"
for FILE in 'find . -type f -name *.jsp -print';
do
sed -e 's/$OLDTAG1/$NEWTAG1/g' -e 's/$OLDTAG2/$NEWTAG2/g' $FILE > temp
mv temp $FILE
done
exit 0
#-------------END BASH ------------------------
Here are the errors:
[jvsaha] site > ./srTags.sh
sed: invalid option -- t
Usage: sed [OPTION]... {script-only-if-no-other-s cript} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
-i[suffix], --in-place[=suffix]
edit files in place (makes backup if extension supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
--help display this help and exit
-V, --version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
E-mail bug reports to: <email address removed>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
mv: invalid option -- t
Try `mv --help' for more information.
[jvsaha] site >
#!/bin/bash
# Filename: srTags.sh
# Find all jsp file
# Search for <!--<~~ tag and replace with <% tag in all jsp files found
# Search for ~~>--> tag and replace with %> tag
OLDTAG1="<!--<~~"
NEWTAG1="<%"
OLDTAG2="~~>-->"
NEWTAG2="%>"
for FILE in 'find . -type f -name *.jsp -print';
do
sed -e 's/$OLDTAG1/$NEWTAG1/g' -e 's/$OLDTAG2/$NEWTAG2/g' $FILE > temp
mv temp $FILE
done
exit 0
#-------------END BASH ------------------------
Here are the errors:
[jvsaha] site > ./srTags.sh
sed: invalid option -- t
Usage: sed [OPTION]... {script-only-if-no-other-s
-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
-i[suffix], --in-place[=suffix]
edit files in place (makes backup if extension supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
--help display this help and exit
-V, --version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
E-mail bug reports to: <email address removed>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
mv: invalid option -- t
Try `mv --help' for more information.
[jvsaha] site >
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER