Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
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 -)

share|improve this question
    
    
@slm, I think it makes more sense to close the other Q as a dupe of this since this one is the broader case. –  Graeme Apr 19 at 20:17
    
@Graeme - I would tend to agree w/ you but the other one has your answer as well, though not as well written. Some merging might be more apt. Maybe we should enlist the help of a mod to help w/ these 2? I'll ping one about it. –  slm Apr 19 at 20:24
    
@slm, I think we can leave it to whoever is going through the close queue and let the crowd decide. The main difference as I see it is that the other Q is a special case of this where you only want one end of the pipe. –  Graeme Apr 19 at 21:27
1  
@Graeme - if we don't prime the pump on it then ppl will likely close the newer to the older as a dup. –  slm Apr 19 at 21:28

1 Answer 1

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.

share|improve this answer
    
This works perfectly. Thank you! –  user65660 Apr 19 at 20:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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