I’ve been using the following call to sed to remove lines files.
sed "/% Program:/,/mode: SPIKE/d" file.tt > file.tt.nh
I tried writing a bash script to allow me to run the script on many files at once. However sed fails.
sed "/% Program:/,/mode: SPIKE/d" file.tt > file.tt.nh
sed: -e expression #1, char 1: unknown command: `"'
This is the script I’ve written that isn’t working
#!/bin/bash
SEDARG='"/% Program:/,/mode: SPIKE/d"';
for F in *.tt
do
OUT=$F'.nh';
echo 'sed '$SEDARG' '$F' > '$OUT;
sed $SEDARG $F > $OUT
done
What perplexes me is if I copy the echo’d string and paste it in the command line it works fine.
Does anyone know why this script is failing but the command line call works?
Quoting is tricky. Basically, move the double quotes from where you assign to
$SEDARGto where you use$SEDARG.