Edit data in pipe with your favorite editor
Each coder has its favorite editor and enjoy to use it whenever possible.
But, when using pipe on unix-based or inspirated OS, text manipulation are only avalaible with programs like sed
or awk
.
The following code is a shell port of the vipe program of Joey Hess's moreutils package, allowing you to edit data in pipe with your favorite editor.
Edit your ~/.bashrc and add following lines:
function vipe()
{
TMP_FILE=$(mktemp);
cat > $TMP_FILE;
[ -n "$EDITOR" ] && $EDITOR $TMP_FILE;
cat $TMP_FILE;
rm $TMP_FILE;
}
Then, refresh your shell if needed:
. ~/.bashrc
Now, with the EDITOR
environment variable pointing to your favorite editor, you can edit data in pipe:
echo 'abcdefgh' | vipe | sed 's/a/1/g'
Written by Sébastien Quioc
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#