I have bunch of ISO images in my hdd and I have their whole content listed inside a text file in the following format:
<immage>.iso, <dir structure>/<filename>.<extension>
example:
OS Backups.iso, ubuntu-12.04-desktop-i386.iso
OS Backups.iso, xubuntu-12.04-desktop-i386.iso
OS Backups.iso, background/pictures.jpg
Pictures vacation 2011.iso, documents/cost_estimates.xls
Pictures vacation 2011.iso, italy/img1.jpg
Pictures vacation 2011.iso, italy/img2.jpg
Now I want to issue a grep command against that text file to find files that contain "pictures" in their names. The expected result would be (for the previous example):
Pictures vacation 2011.iso
OS Backups.iso, background/pictures.jpg
Any ideas on how to accomplish something like this using grep? Alternatives? Thanks!
Here's how to do it with grep, using Perl regular expression syntax
-P
, and the return-only-matching-part switch-o
:which returns:
grep
first checks if it's an.iso
files with "pictures" in its name, which also contains a file with "pictures" in its name, e.g.:.iso
files with "pictures" in its name;Produces the desired output when run as
python test.py index.txt pictures
You can run this script with
python scriptName.py WORDTOLOOKFOR
For example, if I want to check for a line in the textfile containing the word "ubuntu", and the script is named script.py I write the followingBe sure to rename the textfile in the script.
Edit: This will only print the lines containing it, not store it anywhere, much like what grep can do.