grep

Match pattern and put following lines into data structure

Match pattern and put following lines into data structure Question: I have a data feed that I download on a regular bases into a csv. It looks like this TABLE # 196712 / 9000_ >= 10 : 0.002 >= 5 : 0.001 >= 2 : 0.0005 >= 1 : 0.0002 >= 0.5 : 0.0001 >= …

Total answers: 1

Executing linux command using python subprocess

Executing linux command using python subprocess Question: I have a requirement where I need to extract port number from a file example.ini, this file is in linux directory. Now when I am executing below command from CLI its giving exact result which I want $ cat path/example.ini | grep -i variable | cut -d ‘=’ …

Total answers: 1

cat, grep and cut – translated to python

cat, grep and cut – translated to python Question: 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 …

Total answers: 5

grep: write error: Broken pipe with subprocess

grep: write error: Broken pipe with subprocess Question: I get couple of grep:write errors when I run this code. What am I missing? This is only part of it: while d <= datetime.datetime(year, month, daysInMonth[month]): day = d.strftime(“%Y%m%d”) print day results = [day] first=subprocess.Popen(“grep -Eliw ‘Algeria|Bahrain’ “+ monthDir +”/”+day+”*.txt | grep -Eliw ‘Protest|protesters’ “+ monthDir …

Total answers: 4

Grep on elements of a list

Grep on elements of a list Question: I have a list of files names: names = [‘aet2000′,’ppt2000’, ‘aet2001’, ‘ppt2001′] While I have found some functions that can work to grep character strings, I haven’t figured out how to grep all elements of a list. for instance I would like to: grep(names,’aet’) and get: [‘aet2000′,’aet2001’] Sure …

Total answers: 5