Using data from file by embedded language

If we want the embedded language to open a file and use its contents for further processing, then follow this example. We have used the python3  way of opening and reading the contents of a file:

    $ python3 -c "import sys, io; DATA = open('/home/student/sample.txt', 'r').read()" | sed -e "s|Hello|Bye|g" | less
  

In the preceding command-line code, the python3 command is opening and reading contents of a file. Then, it sends the content to the file to bash shell command sed by pipe. Sed replaces text Hello from file to Bye, and finally, it is displayed on screen by the less command.

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.