I have a Perl script using a system call to sort a tsv file:
system("sort -k8 -r -n -t \$'\t' in.txt > out.txt");
It works fine in CentOS and SUSE Linux. But in Ubuntu, it gives an error:
sort: multi-character tab `$\t'
It seems the problem with different OS interpret the quote differently. Do you have a simple but more robust method to sort a tsv file in Perl?
Usually, you’d use an array invocation of
systemto avoid the shell, but you have I/O redirection in the command, which is fiddly to deal with. OTOH,sortallows you to specify the output file with-o, and the named file could be one of the inputs (though it won’t be here):The shell is not invoked; the tab is not mangled. I combined the
-rand-noptions into one; you could leave them separate if you prefer, or (at a pinch) add them after the-k8option.