Quote:
Originally Posted by Gracie Belle
Sed isn't parsing the '*' symbol to automatically expand a variable term
this is what my code looks like
infile=/data/*DTI*/somefile
outfile=/data/*DTI*/tempfile
sed 's/whatever/ever/' "$infile" > "$outfile"
the file paths are actually something like /data/3450_DTI_33452/somefile
if i do echo $infile it prints the path correctly,
however sed reads $infile literally as /data/*DTI*/somefile and thus cannot find the file.
anyone know anyway around this???
help!
|
If you have to matching infile directories:
3450_DTI_33452/somefile
3451_DTI_33452/somefile
The infile will become:
3450_DTI_33452/somefile 3451_DTI_33452/somefile
So the sed line would expand to
sed 's/whatever/ever/' 3450_DTI_33452/somefile 3451_DTI_33452/somefile > 3450_DTI_33452/tempfile 3451_DTI_33452/tempfile
Which isn't what you want. You could either edit them in place:
sed -i 's/whatever/ever/' "$infile"
or use a loop:
for infile in /data/*DTI*/somefile; do
sed 's/whatever/ever/' "$infile" > "${outfile/somefile/tmpfile}"
done