I have a file with about one million lines, like this:
"ID" "1" "2"
"00000687" 0 1
"00000421" 1 0
"00000421" 1 0
"00000421" 1 0
with the last line repeated more than one million times. Taking inspiration from this question, I've tried some of the proposed solutions to see which one is faster. I was expecting that the solutions with only one process would have been faster than those with a pipeline, because they only use one process. But those are the results of my tests:
tail -n +2 file.txt | tr -d \"
$ time tail -n +2 file.txt | tr -d \" 1> /dev/null real 0m0,032s user 0m0,020s sys 0m0,028s
sed '1d;s/"//g' file.txt
$ time sed '1d;s/"//g' file.txt 1> /dev/null real 0m0,410s user 0m0,399s sys 0m0,011s
perl -ne ' { s/"//g; print if $. > 1 }' file.txt
$ time perl -ne ' { s/"//g; print if $. > 1 }' file.txt 1> /dev/null real 0m0,379s user 0m0,367s sys 0m0,013s
I repeated the tests many times and I have always obtained similar numbers. As you can see, tail -n +2 file.txt | tr -d \"
is much faster than the others. Why?