I am getting familiar with sed on the android terminal emulation: the version I am using the sed
included in the toybox which is installed on my unrooted Sony device. sed --version
(or toybox sed --version) gives out the same result:
This is not GNU sed 9.00
Now, I read the specific manual from toybox sed, and tried some simple one liners (the idea is to include those in scripts which I could launch manually). Now the first thing I noticed is that if I try to include the script in simple brackets (es sed -e 's/foo/bar/' file) this is not interpreted correctly.
The command works using the double brackets, but I am having problems with the way scripts are interpreted (or maybe I am doing things wrong). Example. I try to substitute a word inside a file. The file is a string "stringa di test", which I intend to convert into "stringa di prova". The result is that the string is substituted, but the previous string is attached to rest of the line:
user:$ ls
file.txt
n.sh
s.sh
save
script_gian.sh
sed_script
user: $ cat file.txt
stringa di test
user:$sed -i -e "s/test/prova/g" file.txt <
^C1|user:$ cat file.txt
stringa di test
user:$ sed -r -e "s/test/prova/1" file.txt > f.txt <
user:$ ls
f.txt
file.txt
file.txtFD4OVI
n.sh
s.sh
save
script_gian.sh
sed_script
user:$ cat f.txt
stringa di provastringa di test
user:$ cat file.txt
stringa di test
user: $
Another interesting thing is that trying to use the g flag (global) results in sed hanging up and having to be interrupted with CONTROL C. -i command also results in sed hanging up.
I also tried to pipe a string to sed with :
cat file.txt | sed -e "s/foo/bar/" > newfile.txt
But the result is exactly the same. The word inside the string is substituted, and the line as it was before the substitution is appended just after this (this also deletes the remaining characters in the line)-
Am I using sed
wrongly or there is something in the version of sed
I am trying to use?