Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

18
  • 11
    the first one works great! would you mind explaining the logic? im not particularly sure how to interpret the syntax.
    – user479534
    Commented Feb 18, 2011 at 4:24
  • 68
    @user8347: Pipe (|) the message (echo '...') to cat which uses - (standard input) as the first file and todo.txt as the second. cat conCATenates multiple files. Send the output (>) to a file named temp. If there are no errors (&&) from cat then rename (mv) the temp file back to the original file (todo.txt). Commented Feb 18, 2011 at 4:51
  • 1
    @itaifrenkel: I'd have to see what you did, but if cat receives a literal backslash n, it won't convert it to a newline. Something else must have done that. Instead of cat, try piping into hexdump -C to see if you're actually sending backslash and n or if it's a newline. You could also try cat -e to show line endings. Commented Jan 26, 2014 at 21:58
  • 2
    Using 2 and 3 (3 seems simpler to me) allows you to prepend text to many files at once.
    – Felix
    Commented Jan 27, 2014 at 15:24
  • 6
    @Kira: The 1 means do the next command only on line one of the file and the i command is insert. Look in the man page under the "Addresses" section and in the "Zero- or One- address commands" section. Commented Oct 23, 2015 at 16:33