News for hackers. Stuff that matters.
Re:C++ has become a scripting language by MereInterest on Wednesday October 16, 2013 @08:13AM (#6559138)
Python:

    import sys

    data = open(sys.argv[1]).readlines()
    data.sort()
    open(sys.argv[2],'w').write(''.join(data))
Re:C++ has become a scripting language by benhoyt on Wednesday October 16, 2013 @07:29PM (#6562727)
Not bad, however with the ''.join(data) you're effectively doubling the amount of memory needed for large files, because it will build the entire output string in memory (and you've already got the list in memory). Better to use writelines(). You can also use sorted() to iterate over and sort the input lines automatically:

   sorted_lines = sorted(open(sys.argv[1]))
   open(sys.argv[2]).writelines(sorted_lines)