0

I want to grep for a user given queue in all *.idf.txt files under a directory full of subdirectories that include the *.idf.txt files, and store the results so I can later enter those subdirectories.

The grep command I have is below and it works:

cmd = "grep -Rl --include=*.idf.txt " + queue + "/home/labani1/mkann_common/Projects/Expression_Atlas/data"
os.system(cmd)

But how do I do this in a way in which I can save the results to a list or another variable?

2

1 Answer 1

1

You can use command substitution syntax with $(). So, for example,

VAR=`command-name`
VAR="`grep word /path/to/file`"
## or ##

VAR=$(command-name)
VAR="$(grep word /path/to/file)"

Source: https://www.cyberciti.biz/faq/how-to-assign-a-grep-command-value-to-a-variable-in-linuxunix/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.