In my script, I am taking a text file and going through the file line by line and replacing the string "test" with "true", then redirect it to a new file. Here's my code:
cat $FILENAME | while read LINE
do
echo "$LINE" | sed -e `s/test/true/g` > $NEWFILE
done
However when I execute the script I get the following errors:
/home/deploy/KScript/scripts/Stack.sh: line 46: s/test/true/g: No such file or directory
sed: option requires an argument -- e
Usage: sed [OPTION]... {script-only-if-no-other-script} [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)
-c, --copy
use copy instead of rename when shuffling files in -i mode
(avoids change of input file ownership)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-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
--version output version information and exit
Can you please help me find what I am doing wrong ?
$FILENAME
only contains a single filename, you can get rid of the loop and simply do this:sed -e 's/test/true/g' $FILENAME > $NEWFILE
. – doubleDown Jun 13 '13 at 9:54sed 's/test/true/g' $FILENAME > $NEWFILE
. Your current script will result in $NEWFILE having just one line - last one to be exact. – aragaer Jun 13 '13 at 11:49