echo Hello World | nano - | less
I want to modify Hello -> Goodbye while in the the text editor.
It does not have to be with nano. I am stuck with nano reading stdin but requiring me to write to a file (writing to - creates a file named -)
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The moreutils package has a great command for doing this, called
vipe. From the man page:
SYNOPSIS command1 | vipe | command2 DESCRIPTION vipe allows you to run your editor in the middle of a unix pipeline and edit the data that is being piped between programs. Your editor will have the full data being piped from command1 loaded into it, and when you close it, that data will be piped into command2.
By default this will use the
editor command, which is usually just a symlink to the default command line editor. You can change this by either altering the link (use
update-alternatives on Debian based systems) or using the
EDITOR environmental variable. Eg, you could do:
echo Hello World | EDITOR=nano vipe | less
Otherwise, if the particular text editor doesn't have support for this kind of thing, I think you are stuck with manually creating a temporary file, writing the file to that, running the editor, inputting the file to the rest of the pipeline and removing the temporary file. The
vipe command basically takes care of all this. This is nice, but the command is rarely available by default.
If all you want is to replace "Hello" with "Goodbye" (or any other word replacement) you can avoid the manual editing in an editor in favor of automatic search&replace tool. For example "sed" can do such replacements like this:
echo Hello World | sed 's/Hello/Goodbye/' | less
Check "man sed" for more details.
The text editor joe (aka Joe's Own Editor) does what you want.
echo "hello world" | joe - | less functions as expected, although it needs the quotes for some reason.
Some commands (such as gpg) produce displayed output that does not enter the pipe. This corrupts the initial display inside of joe, but hitting ctrl+r -- refresh -- will clean things up.