0

I am on FreeBSD 13 using csh and I have a notes.txt file which I would like to be able to append notes to, quickly, from the command line. I would like to be able to add two 'new lines' before each note that I append, in order to separate the notes, making them easier to distinguish from each other. So, my question is "How can I append two new lines before and while appending a string of text to a file and how can I do this from the command line?"

Thanks for any help, -Jonathan

Jon Stier
  • 1
  • 1
  • `printf "\n%s\n" "your new note" >> notes_file.txt`? (you can use a variable, e.g. `"$note"` for `"your new note"` if you like) That will add a blank like and then your new note, appending it to `notes_file.txt`. If you want two blank lines, the `printf "\n\n..."` Note for `csh` output redirection can be written as `> >` with a space in between. – David C. Rankin Apr 26 '22 at 03:31
  • Note: by appending a newline before AND after, each new note will have a newline in between and your file will be POSIX compliant with a `'\n'` after the final line of text.. – David C. Rankin Apr 26 '22 at 03:37
  • Is there an command line option to append a date or will I just have to do that manually? – Jon Stier Apr 26 '22 at 03:42
  • `printf "\n%s %s\n" \`date +%F %T\` "your new note" >> notes_file.txt` where `\`date +%F %T\`` is a *command-substitution* that produces a date in the format `2022-04-25 22:46:01` and it is substituted before the new note. The POSIX form of command substitution is `$(...)` command -- but I'm not sure that works in csh. If it does, use that instead of backticks around the date command. – David C. Rankin Apr 26 '22 at 03:46
  • Lots of thanks to you, David! – Jon Stier Apr 26 '22 at 03:48
  • Does this answer your question? [How to append output to the end of a text file](https://stackoverflow.com/questions/6207573/how-to-append-output-to-the-end-of-a-text-file) – F. Hauri - Give Up GitHub Apr 26 '22 at 05:38

1 Answers1

0
cat > newnote <<EOF
$a


Your new note.
.
wq
EOF

ed -s notes.txt < newnote
petrus4
  • 616
  • 4
  • 7