1

It's about a program that works iteratively - gets input from stdin and pass the results over the stdout. There is a set a know text that need to be passed to this program and I've put them in a file begin.txt. So I can setup a pipe

cat begin.txt - | myprogram

The problem arrive later - if I want to send something that I already typed (with slight modification), the arrows doesn't work, because there is no history in cat

  1. Therefore I am looking for something that will keep the history per line.

Initially I've tried with vim and :.! myprogram but then after executing the entry (passed text) myprogram exits and then its status get lost. I need a way to keep the program working till passing my text/commands.

  1. Is it possible to run vim in a way to act as a filter in a pipe in such continuous way?

2 Answers 2

3

Use rlwrap. The rlwrap utility wraps whatever utility you use it on so that it acquires a ReadLine history (along with some ReadLine editing capabilities like what you are used to from the bash prompt). It will store the history in a file under $RLWRAP_HOME (or $HOME if that variable is not set).

With rlwrap, you would be able to do

rlwrap cat begin.txt - | myprogram

The next time you run this, you will have a basic history that you can scroll in with you Up-arrow and Down-arrow keys. The history would by default be stored in ~/.cat_history.

See the manual for rlwrap (man rlwrap) for further information.

-1
cat begin.txt - << EOF
Type the 
text you want
here, terminated by a line with only
EOF

See https://stackoverflow.com/q/2500436 for more details on how this works.

Everything you type as part of this will be stored in bash history, so you can edit it to your hearts content.

If you want something more flexible, why not just create a temporary file, and edit that?

cat begin.txt > /tmp/myprograminput
editor /tmp/myprograminput
cat /tmp/myprograminput | myprogram

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.