1

I'm running this command to append output text data to a markdown file:

git log -1 --oneline --skip=1 | tee -a page1.md

For the most part functionality is great, but I need to format the output so its readable. Right now, the command above is appending the markdown file like so:

Append1 Append2 Append3

I need it to be formatted as such:

Append1
Append2
Append3

With each time the command being run, a new line is created and populated with the git log information.

thank you for any guidance on the matter.

4
  • How about git log -1 --oneline --skip=1 | tee -a page1.md | tr " " "\n"?
    – Ar Rakin
    Jun 7, 2022 at 18:11
  • Why not use bash output redirection like git log -1 --oneline --skip=1 >> page1.md?
    – user68186
    Jun 7, 2022 at 18:58
  • These examples work, but not the way you would expect to a markdown file.
    – andres
    Jun 7, 2022 at 20:01
  • @ArRakin Does your command append \n at the end of the git log?
    – andres
    Jun 7, 2022 at 20:11

2 Answers 2

2
git log -1 --oneline --skip=1 | tee -a page1.md
echo >> page1.md

The echo will append a single newline.
I'm assuming --oneline does indeed add a single line for each invocation.



Alternative, single line:

git log -1 --oneline --skip=1 | tee -a page1.md && echo >> page1.md
1

The Hannu's answer looks correct, but if you want to perform it as single line command - one of the possible ways is to use the cat command and process substitution like this:

cat <(git log -1 --oneline --skip=1) <(echo) | tee -a page1.md

It looks like you are using this frequently so you can add the following function at the bottom of your ~/.bashrc file:

function git-log-1 () { cat <(git log -1 --oneline --skip=1) <(echo) | tee -a "$1"

Then do source ~/.bashrc or open a new terminal and use the function as shell command:

git-log-1 page1.md

You must log in to answer this question.

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