Hi There,

I'm very new to Python. Is there a easy way of looping trhough a file and using the values in a grep command?

Value A              Value B
2011-12-14 20:54:09, 797410378,
2011-12-14 20:55:52, 734451141,
2011-12-14 20:56:30, 796058907,
2011-12-14 20:59:51, 736280553,
2011-12-14 21:09:42, 729858848,
2011-12-14 21:12:02, 825895818,
2011-12-14 21:13:53, 828495337,
2011-12-14 21:25:31, 820533082,
2011-12-14 21:32:08, 730805414,
2011-12-14 21:56:05, 710672381,

grep ValueA File.txt | grep ValueB

Regards

Recommended Answers

All 3 Replies

It's not exactly a python question, although your problem could probably be programmed in python. Apparently you are trying to extract something from File.txt using the 2 columns ValueA and ValueB. Can you explain with more details the contents of File.txt and the expected output ?

Hi Gribouillis,

The following is the content of File.txt

2011-12-14 20:54:09, 797410378,
2011-12-14 20:55:52, 734451141,
2011-12-14 20:56:30, 796058907,
2011-12-14 20:59:51, 736280553,
2011-12-14 21:09:42, 729858848,
2011-12-14 21:12:02, 825895818,
2011-12-14 21:13:53, 828495337,
2011-12-14 21:25:31, 820533082,
2011-12-14 21:32:08, 730805414,
2011-12-14 21:56:05, 710672381,

Regards

If you are using python, you dont need a grep command for this

from __future__ import print_function
valueA = '2011-12-14'
valueB = '825895818'

with open('File.txt') as ifh:
    for line in ifh:
        if valueA in line and valueB in line:
            print(line, end='')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.