The bash shell offers many different ways to filter text and modify the output of a command. This is useful when a the user is creating a complex script and manipulating a text stream is required.
This example uses Python to search and replace the word ‘linux’ with ‘GNU/Linux’.
ubuntu ~ $ echo "linux is fun." | python -c 'import sys;print sys.stdin.read().replace("linux","GNU/Linux")' |
Another example, this time using Perl.
ubuntu ~ $ echo "linux is fun." | perl -pe 's.linux.GNU/Linux.g' GNU/Linux is fun. |
This final example shows how to use the sed command to filter text.
ubuntu ~ $ echo "linux is fun." | sed "s/linux/GNU\/Linux/gi;" GNU/Linux is fun. |