[Tutor] how to grep a word and make a dictionary from multiple lines.
Danny Yoo
dyoo at hashcollision.org
Mon Jan 4 18:09:07 EST 2016
On Mon, Jan 4, 2016 at 2:29 PM, Fosiul Alam <fosiul at gmail.com> wrote:
> Hi Expert,
> I am learning python to do some system admin code, i am still in the
> process of learning but I need a help on bellow code in urgent, i will be
> really greatfull for any help
Question: how would you do this task with regular Unix tools? (i.e.
grep, cut, and other shell tools)?
> grep a line which has 1:0:0:129 , and get the LUN number(i.e
> 360060165656565634348a739e511) for this path
You may want to look at the fileinput library, which automates
processes the lines of input files:
https://docs.python.org/3.0/library/fileinput.html
along with string methods to check whether a line matches a given
criterion or not. See the Python tutorial for examples:
https://docs.python.org/3/tutorial/introduction.html#strings
For your case, you might find the 'in' operator helpful for checking
for substring match:
#################################
>>> 'hello' in 'this is a test hello world'
True
>>> 'hola' in 'this is a test hello world'
False
#################################
More information about the Tutor
mailing list