Help needed sed: illegal option -- i

hello. i have a script, but in solaris i get this message sed: illegal option -- i
whats wrong? With Ubuntu there is no problem. Thanks for help.

#!/bin/bash
for file in $(find /directory..../Test/*.txt -type f)
do
head -n 1 $file | egrep '^#!'

if [ $? -eq 0 ] 
    then
sed -i '2i\Headertext' $file
sed -i '1i\Headertext' $file

fi
done


Ubuntu has GNU sed which has the -i option. Sed on Solaris does not.

try:

/usr/xpg4/bin/sed '2i\
Headertext' "$file" > "$file.new" && mv "$file.new" "$file"

etc.

1 Like

Hi.

See also use of utility and / or perl script sponge in Sed does not make changes in the file but to the standard output , post # 4 ... cheers, drl

Hello. Tank you. It works. But how can i make it possible, that the HEADERTEXT will be inserted in a directory and all subfolder . At the moment the script writes only in .txt files from directory Test.....

Many thanks