I came across some strange behavior when executing certain Linux commands on different machines. The commands are the ones I provided in the my answer to this question
When I run in Bash and on my Macbook Pro, I get the following results:
$ ls
test.txt test2.txt test3.txt test4.txt
$ (ls *.txt > output) && (sed -i -e 's/^/-v /' output)
$ ls
output test.txt test3.txt
output-e test2.txt test4.txt
$ cat output
-v test.txt
-v test2.txt
-v test3.txt
-v test4.txt
$ cat output-e
test.txt
test2.txt
test3.txt
test4.txt
There are two files generated – output and output-e.
Now, output-e just has the name of the *.txt files (this is not expected), but the other one has the proper output with the "-v" in front (which is the expected output).
However, when I run this on a Linux system, it simply just gives me the correct output file. Does anyone know what might be causing this extra file output-e to be generated?
>Solution :
You are using BSD version of sed. The option -i takes an argument that specifies the suffix of the backup file. You specified -e as the suffix, so a backup file output-e is created.