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.

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

1 Answers1

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.

strugee
  • 14,951
  • 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 06: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 06: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 '13 at 06:49