0

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.

3
  • I've edited out your additional questions. It's bad practice on Stack Exchange to combine questions like this.
    – strugee
    Sep 19, 2013 at 6:19
  • Sorry. Is there any way to delete the question? So that I can redo it. Sep 19, 2013 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, 2013 at 6:24

1 Answer 1

0

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.

3
  • 1
    This will result in an empty foo. The shell will open foo for writing and truncate it before sort even starts Sep 19, 2013 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 Sep 19, 2013 at 6:43
  • @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, 2013 at 6:49

Not the answer you're looking for? Browse other questions tagged .