Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I have this homework question. I looked at the man page for sort and I believe the answer is -o, --output=FILE Is that correct?

It is a Fedora server.

We're supposed to look on man pages, if there is no man page related to the subject than use an info page. If no info page exists either than use the internet.

share|improve this question
    
I've edited out your additional questions. It's bad practice on Stack Exchange to combine questions like this. –  strugee Sep 19 '13 at 6:19
    
Sorry. Is there any way to delete the question? So that I can redo it. –  user2227702 Sep 19 '13 at 6:21
    
No, you don't have to delete it. I edited it for you (it'll be approved by the community soon) but in the future you can edit your question right under the tags. And welcome to Stack Exchange! –  strugee Sep 19 '13 at 6:24
add comment

marked as duplicate by Michael Mrozek Sep 19 '13 at 6:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

Sorting a file named foo in place - sort of:

set TMP=$(mktemp)
sort foo > $TMP
mv $TMP foo

This redirects the output of sort into a temporary file, which then replaces foo.

share|improve this answer
1  
This will result in an empty foo. The shell will open foo for writing and truncate it before sort even starts –  Michael Mrozek Sep 19 '13 at 6:28
1  
This works, but I wouldn't exactly call writing the whole thing out to a new file "in-place" :). On the other hand, it's the same thing -o does, and that's clearly what the teacher expected –  Michael Mrozek Sep 19 '13 at 6:43
    
Thanks everyone –  user2227702 Sep 19 '13 at 6:47
    
@user2227702 you don't have to thank people - instead, upvote! (You can't do this yet but it's only 5 rep) –  strugee Sep 19 '13 at 6:49
add comment

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