1

1. Summary

I don't find, what can I do, that text output to multiple files, if by default in CLI program stdout to file.

2. Example

I use generate-changelog package. In this package by default output print to file, not to console.

3. Expected behavior

I want to add same output to 2 files:

  • SashaVersion.txt — file, in which I want to add stdout only one time;
  • CHANGELOG.md — file, in which I want to add stdout multiple times; this file not must overwrite.

4. Not helped

  1. Double using -f argument — changelog -f SashaVersion.txt -f CHANGELOG.md.
  2. tee command, for example, — changelog -f | tee SashaVersion.txt CHANGELOG.md.
  • 1
    How did tee not do what you appear to have wanted it to do? – DopeGhoti Jan 24 '18 at 15:40
  • @DopeGhoti: possibly, tee solve this task, but I don't find, what can I do. In 4.2 example tee create blank file SashaVersion.txt, without content. Thanks. – Саша Черных Jan 24 '18 at 15:43
5

From the page you linked to:

Options:

-f, --file [file] file to write to, defaults to ./CHANGELOG.md, use - for stdout

Note that dash, it's quite a common way of marking stdin/stdout.

Based on that text, this would probably work:

$ changelog -f - | tee SashaVersion.txt CHANGELOG.md

Though it would still print one copy of the output to the terminal, so either of these to inhibit that:

$ changelog -f - | tee SashaVersion.txt > CHANGELOG.md
$ changelog -f - | tee SashaVersion.txt CHANGELOG.md > /dev/null

If -f - doesn't work, try -f /dev/stdout.


Of course, if you're running zsh, you don't even need tee:

zsh$ changelog -f - > SashaVersion.txt > CHANGELOG.md

In all of those, replace > with >> if you want the new text to be appended to the file as opposed to overwriting the file. If you wanted the output to overwrite SashaVersion.txt, and also be appended to CHANGELOG.md as well as being written on stdout, you could do:

$ changelog -f - | tee SashaVersion.txt | tee -a CHANGELOG.md

Or with zsh:

$ changelog -f - >&1 > SashaVersion.txt >> CHANGELOG.md
  • I'm sorry, I read npm-changelog documentation, but I thought, that - is hyphen or dash, not command line argument. – Саша Черных Jan 24 '18 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.