0

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!

3
  • If you're running out of diskspace as you write out the sorted data then no. Commented Jun 26, 2013 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 Commented Jun 26, 2013 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). Commented Jun 26, 2013 at 8:56

1 Answer 1

1

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)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.