maybe there are enough questions and/or solutions for this, but I just can't help myself with this one question: I've got the following command I'm using in a bash-script:
var=$(cat "$filename" | grep "something" | cut -d'"' -f2)
Now, because of some issues I have to translate all the code to python. I never used python before and I have absolutely no idea how I can do what the postet commands do. Any ideas how to solve that with python?
Best Answer
You need to have better understanding of the python language and its standard library to translate the expression
cat "$filename": Reads the file
cat "$filename"
and dumps the content to stdout|
: pipe redirects thestdout
from previous command and feeds it to thestdin
of the next commandgrep "something": Searches the regular expression
something
plain text data file (if specified) or in the stdin and returns the matching lines.cut -d'"' -f2: Splits the string with the specific delimiter and indexes/splices particular fields from the resultant list
Python Equivalent
Combining