- Feb 21, 2013
- 2,650
- 4
- 81
Hey everyone,
I'm trying to write a bash script to replace a few strings in a text file of html, with some user defined stuff. I have a text file that has a marker, "XXX", where I'd like to pop in a number from a command line argument.
It seemed like 'sed' was the right tool for the job, so I tried something like this.
str1="XXX"
str2="$1"
reffile="ref_file.txt"
newfile="new_file.txt"
cp $reffile $newfile
sed "s/$str1/$str2/nwg $newfile"
with options:
s - substitution
n - suppress output to terminal
w - write them to file
g - do all matches
But when I actually run it, I get:
sed: -e expression #1, char 24: unknown option to 's'
And I don't really understand what that means, I thought that maybe there were somehow slashes in the string created by the "", and so I tried swapping my '/' in the sed command with '@', but that seems to give the same error.
The file ref_file.txt and new_file.txt both have lots of html tags, '<>', "", etc, could that be a problem?
I'm trying to write a bash script to replace a few strings in a text file of html, with some user defined stuff. I have a text file that has a marker, "XXX", where I'd like to pop in a number from a command line argument.
It seemed like 'sed' was the right tool for the job, so I tried something like this.
str1="XXX"
str2="$1"
reffile="ref_file.txt"
newfile="new_file.txt"
cp $reffile $newfile
sed "s/$str1/$str2/nwg $newfile"
with options:
s - substitution
n - suppress output to terminal
w - write them to file
g - do all matches
But when I actually run it, I get:
sed: -e expression #1, char 24: unknown option to 's'
And I don't really understand what that means, I thought that maybe there were somehow slashes in the string created by the "", and so I tried swapping my '/' in the sed command with '@', but that seems to give the same error.
The file ref_file.txt and new_file.txt both have lots of html tags, '<>', "", etc, could that be a problem?