The syntax highlighting here should be a good indicator of what your problem is -- you've got several strings smashed together with content that isn't in the strings. Try replacing this:
cq_fname="%let outputfile="/user/cq_"$1".csv";"
with this:
cq_fname="%let outputfile=\"/user/cq_$1.csv\";"
I escaped the "
inside the string with \
characters and removed the "
characters that felt like they probably don't exist in the filename.
Alok suggests using a different character for the replacement command -- that's necessary.
Also, you need to use the same variable name in both the assignment and the string. (D'oh!)
The final script is:
#!/bin/bash
cq_fname="%let outputfile=\"/user/cq_$1.csv\";"
sed "29s|.*|$cq_fname|" file1.sas > file2.sas
I found the mis-matched variable names by adding set -x
to the top of the script; it showed the execution output of the script along the way.
Broken:
$ ./replace
+ cq_fname='%let outputfile="/user/cq_.csv";'
+ sed '29s|.*||' file1.sas
Fixed:
$ ./replace
+ cq_fname='%let outputfile="/user/cq_.csv";'
+ sed '29s|.*|%let outputfile="/user/cq_.csv";|' file1.sas
set -x
is a superb little debugging tool, when you need it.