0

Is it possible to use sed and awk kind of commands in python that works on windows operating system? For Unix operating system we can import os package and use os.system to perform any unix operations. I want the same kind of operations to be performed in Windows operating system. Can anyone please let me know if there is any such package that can be used in python.

P.S. I want to perform such actions as part of .py script instead of having them executed in command lines as in IPython.

As an example, I want this kind of CODE to be executed in Windows operating system.

import os
os.system("sed -ie 's/ow/aagh/g' ~/temp.txt")

2 Answers 2

1

Yes, this works. However, you will need to install the unix programs you want to run on windows.

For example, you can find sed here: http://gnuwin32.sourceforge.net/packages/sed.htm

To have most of the common unix commands available on windows, have a look here: https://www.cygwin.com/

Sign up to request clarification or add additional context in comments.

Comments

0

As stated in the other answer: yes, you can do that if you want force your users (or yourself) to install the appropriate linux commands also on windows.

However if you really want to make it a portable script you'll have to use the appropriate python modules in order to achieve the same goal. See for instance this question and its answers python equivalent to sed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.