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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.