Issue
I have a shell command that provides output that I would like to edit before piping it into another command. This is not regular output that can easily be edited with sed
and such. My current approach is:
command-one > tmp
vim tmp
command-two < tmp
rm tmp
I would like to avoid the unnecessary creation of a temporary file and instead do something like command-one | vim - | command-two
but that doesn't work because the actual onscreen output of vim gets piped into the command instead of being visible for me to edit. This works in commands like git commit
which wait for the temp file to be written before using the result.
Solution
If you want to use some random editor (i.e. the value of $EDITOR
), you'll need to use a temporary file. Most editors do not have the facility to accept an entire file on stdin
and write it to stdout
when the edit is finished.
See mktemp
(or tempfile
in the unlikely case that you don't have mktemp
) for a safe way to create a temporary file.
Answered By - rici Answer Checked By - Pedro (WPSolving Volunteer)