Marty Wallace
Marty Wallace

Reputation: 35734

Linux command line output appended to file with new line

What is the best way to output the date into a file plus a blank line and have vi ready to go at the new line:

So far i have:

date >> myfile && vi myfile

But it doesnt do 2 things:

  1. Adds the new line
  2. Starts editing at the end of the file

Upvotes: 0

Views: 108

Answers (2)

Peter Cordes
Peter Cordes

Reputation: 364288

Initial editing position:
+[num] starts editing at the specified line number, or EOF if omitted. Many editors support this, so they can be invoked from less at the current view position.

Getting an extra newline: Either use a custom format for date that ends with two newlines, or do:

{ date && echo; } >> myfile && vi + myfile

Upvotes: 4

Petr Skocik
Petr Skocik

Reputation: 60068

date >> myfile && vi -c 'normal Go' myfile

This is a way.

Upvotes: 1

Related Questions