-2

I am fairly new to sed and am trying to use sed to insert a user inputed line as the first line in another text file. The shell script I am try to use is:

echo -n "Enter values: "
read text
echo "You entered: $text"

sed  -i '1i $text' $file

The return I get is:

"sed: -i may not be used with stdin"

1 Answers1

0

I made this example.sh :

#!/bin/bash
file="new.txt"
echo>$file # the file must not be empty, as sed needs a stream to work with
echo -n "Enter values: "
read text
echo "You entered: $text"
sed -i "\$a$text" $file

Explanation :

The escaped $ refers to the last line, and a is the command to append.
I guess you're trying to learn sed, but obviously you should prefer echo with >> instead.

Rémi T.
  • 15
  • 6