Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a huge file that needs to be sorted in Linux, for example:

sort -k1,1 -k2,2n /dir/fileA.sam > /dir/fileA_sorted.sam

Because I ran out of disk space, is there a way to delete the original file (i.e. fileA.sam) after sorting it and output fileA_sorted.sam? Thanks!

share|improve this question
    
If you're running out of diskspace as you write out the sorted data then no. –  tink Jun 26 '13 at 2:17
    
You can always use an alternative disk / usb key / ram disk to get round a problem of space on a temp file –  davidgo Jun 26 '13 at 6:15
    
I don't understand your question. If the sort succeeded and you don't need the unsorted file, then you can delete it (using rm). Of course you can output the sorted file (to the screen, to a printer, to whatever). –  Werner Henze Jun 26 '13 at 8:56

1 Answer 1

up vote 1 down vote accepted

You can run a second command after running the first command by using a "&&" to separate them (or other characters, but using && implies it will only run the second command if the first succeeds)

sort -k1,1 -k2,2n /dir/fileA.sam > /dir/fileA_sorted.sam && rm /dir/fileA.sam

(No warranty express or implied, try first with something innocuous before running rm)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.