Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-12 Thread Chris Angelico
On Mon, Nov 12, 2018 at 11:20 PM Anssi Saari wrote: > > Chris Angelico writes: > > > On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari wrote: > >> > >> Chris Angelico writes: > >> > >> > No helper needed. Safe against command injection. Uses the known > >> > format of the command's output; if you wan

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-12 Thread Anssi Saari
Chris Angelico writes: > On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari wrote: >> >> Chris Angelico writes: >> >> > No helper needed. Safe against command injection. Uses the known >> > format of the command's output; if you want other information as well >> > as the type, you could get that too.

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-09 Thread Cousin Stanley
srinivasan wrote: > Even after changing as per the below > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > or: > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > or: > "blkid -o export %s | grep \&quo

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-09 Thread Chris Angelico
On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari wrote: > > Chris Angelico writes: > > > No helper needed. Safe against command injection. Uses the known > > format of the command's output; if you want other information as well > > as the type, you could get that too. > > Can someone let me in on this

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-09 Thread Anssi Saari
Chris Angelico writes: > No helper needed. Safe against command injection. Uses the known > format of the command's output; if you want other information as well > as the type, you could get that too. Can someone let me in on this secret helper module? Doesn't seem to match the helper module in

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread srinivasan
I feel I have kick started my learning in python :) Have a great day ahead! On Wed, Nov 7, 2018 at 3:11 PM Ben Bacarisse wrote: > srinivasan writes: > > > Even after changing as per the below > > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" &

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread Ben Bacarisse
srinivasan writes: > Even after changing as per the below > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > or: > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > or: > "blkid -o export %s | grep \&qu

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread Chris Angelico
On Wed, Nov 7, 2018 at 11:42 PM srinivasan wrote: > > Some I managed to fix temporarily as below, might be useful for others. Also > please correct me if anything wrong or for any improvements in the below > > cmd = "blkid -o export %s" % partition_path > out = self._helper.execut

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread srinivasan
nivasan wrote: > > > Even after changing as per the below > > > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > > > or: > > > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > > > or: > >

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread Chris Angelico
On Wed, Nov 7, 2018 at 11:36 PM Qian Cai wrote: > > srinivasan wrote: > > Even after changing as per the below > > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > > or: > > 'blkid -o export %s | grep "TYPE" | cut -

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread Qian Cai
srinivasan wrote: > Even after changing as per the below > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" > or: > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' > or: > "blkid -o export %s | grep \&quo

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread srinivasan
Even after changing as per the below "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" or: 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3' or: "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3" S

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread Brian J. Oney via Python-list
On Wed, 2018-11-07 at 10:22 +0100, srinivasan wrote: > blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3 You don't need to escape the single quotes. Try either: "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3" or: 'blkid -o e

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread srinivasan
After changing the line to *"cmd = "blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3" % fs"*, Now I dont see the error "SyntaxError: can't assign to literal" This is not returning exactly "*vfat*" instead of this, it is return

Re: SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-06 Thread Rhodri James
On 06/11/2018 18:10, srinivasan wrote: root:~/qa/test_library# python3 sd.py File "sd.py", line 99 *cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)* * ^* *SyntaxError: can't assign to literal* Look at the 'c

SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-06 Thread srinivasan
:return: filesystem type as string or None if not found """ *cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)* *return self._helper.execute_cmd_output_string(cmd)* *def execute_cmd_output_string(sel

Re: how to grep

2017-08-04 Thread dieter
Iranna Mathapati writes: > How to grep values from below out put string. > > pattern should include "Fabric Module". One possible way would be to use a regular expression -- see the documentation for the "re" module. -- https://mail.python.org/mailman/listinfo/python-list

Re: how to grep

2017-08-04 Thread Steve D'Aprano
On Fri, 4 Aug 2017 10:33 pm, Iranna Mathapati wrote: > Hi Team, > > How to grep values from below out put string. > > pattern should include "Fabric Module". > > grepping Fabric module values only > > str = ''' > 22 0Fabric Modul

how to grep

2017-08-04 Thread Iranna Mathapati
Hi Team, How to grep values from below out put string. pattern should include "Fabric Module". grepping Fabric module values only str = ''' 22 0Fabric Module J8N-C9508-FM ok 24 0Fabric ModuleJ8N-C95

Re: Using re to perform grep functionality in Python

2017-03-01 Thread Michael Torrie
On 03/01/2017 02:55 PM, rob...@forzasilicon.com wrote: > Obviously, not what I want. Can anyone feed some input? You've already got some good answers, but I just wanted to point you at this good resource: http://www.dabeaz.com/generators/ Pretty much anything you do in a shell script that involv

Re: Using re to perform grep functionality in Python

2017-03-01 Thread Cameron Simpson
pt uses an external call to grep via subprocess, but I would like to internalize everything to run in Python. I've read that re can accomplish the filtering, but I am having trouble getting it to duplicate what I already have. # USING EXTERNAL GREP # # display RAID controller inf

Re: Using re to perform grep functionality in Python

2017-03-01 Thread robert
Thanks, Chris. That was nice and easy and very simple. -- https://mail.python.org/mailman/listinfo/python-list

Re: Using re to perform grep functionality in Python

2017-03-01 Thread Chris Angelico
pt in cron. The > script uses an external call to grep via subprocess, but I would like to > internalize everything to run in Python. I've read that re can accomplish the > filtering, but I am having trouble getting it to duplicate what I already > have. > > p = subprocess.Pop

Using re to perform grep functionality in Python

2017-03-01 Thread robert
Hi All, I'm relatively new to Python, and I am having some trouble with one of my scripts. Basically, this script connects to a server via ssh, runs Dell's omreport output, and then externally pipes it to a mail script in cron. The script uses an external call to grep via subproc

Re: What does “grep” stand for?

2015-11-06 Thread Larry Hudson via Python-list
On 11/06/2015 05:25 AM, William Ray Wing wrote: On Nov 5, 2015, at 10:36 PM, Larry Hudson via Python-list wrote: [snip] You’re not REALLY an old timer unless you’ve used TECO. -Bill Agreed. I'm not really and old-timer, just old (I'm 78). My first exposure to computers was the MITS Al

Re: What does “grep” stand for?

2015-11-06 Thread William Ray Wing
> On Nov 5, 2015, at 10:36 PM, Larry Hudson via Python-list > wrote: > > On 11/05/2015 05:18 PM, Dennis Lee Bieber wrote: >> On Thu, 5 Nov 2015 20:19:39 + (UTC), Grant Edwards >> declaimed the following: >> >>> Though I used a line-editor for a while on VMS, I was never very good >>> at i

Re: What does ???grep??? stand for?

2015-11-06 Thread Grant Edwards
On 2015-11-06, Dennis Lee Bieber wrote: > On Thu, 5 Nov 2015 20:19:39 + (UTC), Grant Edwards > declaimed the following: > >>Though I used a line-editor for a while on VMS, I was never very good >>at it, and abanded it for a full-screen editor at he first >>opportunity. But, if you ever get a

Re: What does “grep” stand for?

2015-11-05 Thread Dan Sommers
On Thu, 05 Nov 2015 19:36:11 -0800, Larry Hudson wrote: > Anyone besides me remember the CP/M editor Mince (Mince Is Not > Complete EMACS)? It was an emacs-like editor, without any e-Lisp or > other way of extending it. I believe it was my first exposure to a > screen-oriented editor. I quite l

Re: What does “grep” stand for?

2015-11-05 Thread Larry Hudson via Python-list
On 11/05/2015 05:18 PM, Dennis Lee Bieber wrote: On Thu, 5 Nov 2015 20:19:39 + (UTC), Grant Edwards declaimed the following: Though I used a line-editor for a while on VMS, I was never very good at it, and abanded it for a full-screen editor at he first opportunity. But, if you ever get a

Re: What does “grep” stand for?

2015-11-05 Thread Grant Edwards
On 2015-11-05, Random832 wrote: > Grant Edwards writes: >> On 2015-11-05, Random832 wrote: >>> Of course, both of those things are also true of ed. >> >> Well, maybe not for you. I knew people who (yonks ago) used 'ed' for >> regular file editing. And I remember using the VMS line-editor for >

Re: What does “grep” stand for?

2015-11-05 Thread Random832
Grant Edwards writes: > On 2015-11-05, Random832 wrote: >> Of course, both of those things are also true of ed. > > Well, maybe not for you. I knew people who (yonks ago) used 'ed' for > regular file editing. And I remember using the VMS line-editor for > regular file editing for a couple years

Re: What does “grep” stand for?

2015-11-05 Thread Grant Edwards
On 2015-11-05, Random832 wrote: > Chris Angelico writes: >> As someone who grew up on MS-DOS, I'd like to mention that EDLIN's >> value wasn't in the obvious places. There were two features it had >> that most other editors didn't: firstly, it would read only as much >> of the file as it needed,

Re: What does “grep” stand for?

2015-11-05 Thread Random832
Chris Angelico writes: > As someone who grew up on MS-DOS, I'd like to mention that EDLIN's > value wasn't in the obvious places. There were two features it had > that most other editors didn't: firstly, it would read only as much of > the file as it needed, so you could edit a file larger than av

Re: What does “grep” stand for?

2015-11-05 Thread Chris Angelico
On Thu, Nov 5, 2015 at 6:32 PM, Christian Gollwitzer wrote: > The point I'm so amused is, that MS has not felt the need to ship a real > editor, and also cut back on most of the other tools that make computing, > even on commandlines, a pleasant experience. Readline? Tab-Completion? I > read a mag

Re: What does “grep” stand for?

2015-11-04 Thread Christian Gollwitzer
Am 05.11.15 um 01:42 schrieb Chris Angelico: On Thu, Nov 5, 2015 at 6:38 AM, Christian Gollwitzer wrote: As someone who grew up on MS-DOS, I'd like to mention that EDLIN's value wasn't in the obvious places. There were two features it had that most other editors didn't: firstly, it would read on

Re: What does “grep” stand for?

2015-11-04 Thread Chris Angelico
On Thu, Nov 5, 2015 at 6:38 AM, Christian Gollwitzer wrote: > Am 04.11.15 um 19:24 schrieb Ben Finney: >> >> The name is a mnemonic for a compound command in ‘ed’ [0], a text editor >> that pre-dates extravagant luxuries like “presenting a full screen of >> text at one time”. >> >> [... lots of f

Re: What does “grep” stand for?

2015-11-04 Thread Christian Gollwitzer
Am 04.11.15 um 19:24 schrieb Ben Finney: The name is a mnemonic for a compound command in ‘ed’ [0], a text editor that pre-dates extravagant luxuries like “presenting a full screen of text at one time”. [... lots of fun facts ...] Here is another fun fact: The convincing UI of ed was actually

Re: What does “grep” stand for? (was: Regular expressions)

2015-11-04 Thread Tim Chase
On 2015-11-05 05:24, Ben Finney wrote: > A very common command to issue, then, is “actually show me the line > of text I just specified”; the ‘p’ (for “print”) command. > > Another very common command is “find the text matching this pattern > and perform these commands on it”, which is ‘g’ (for “g

What does “grep” stand for? (was: Regular expressions)

2015-11-04 Thread Ben Finney
Steven D'Aprano writes: > On Wednesday 04 November 2015 13:55, Dan Sommers wrote: > > > Its very name indicates that its default mode most certainly is > > regular expressions. > > I don't even know what grep stands for. “grep” stands for ‘g/RE/p’. The

Re: Using sh library with grep command

2013-11-23 Thread Luca Fabbri
On Sat, Nov 23, 2013 at 5:29 PM, Peter Otten <__pete...@web.de> wrote: > Luca wrote: > >> I'm trying to use sh (https://pypi.python.org/pypi/sh) for calling >> system grep command but it's now working as expected. >> >> An example: >> >

Re: Using sh library with grep command

2013-11-23 Thread Peter Otten
Luca wrote: > I'm trying to use sh (https://pypi.python.org/pypi/sh) for calling > system grep command but it's now working as expected. > > An example: > > import sh > sh.grep('abc', os.getcwd(), '-r') > > But I get the ErrorRet

Re: Using sh library with grep command

2013-11-23 Thread Roy Smith
In article , Luca wrote: > I'm trying to use sh (https://pypi.python.org/pypi/sh) for calling > system grep command but it's now working as expected. > > An example: > > import sh > sh.grep('abc', os.getcwd(), '-r') > > But

Using sh library with grep command

2013-11-23 Thread Luca
I'm trying to use sh (https://pypi.python.org/pypi/sh) for calling system grep command but it's now working as expected. An example: import sh sh.grep('abc', os.getcwd(), '-r') But I get the ErrorReturnCode_1: exception, that I learned is the normal exit

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-11 Thread Xah Lee
On Feb 11, 2:06 am, Alexander Gattin wrote: > Hello, > > On Tue, Feb 08, 2011 at 05:32:05PM +, Icarus > > Sparry wrote: > > The key thing which makes this 'modern' is the > > '+' at the end of the command, rather than '\;'. > > T

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-11 Thread Alexander Gattin
Hello, On Tue, Feb 08, 2011 at 05:32:05PM +, Icarus Sparry wrote: > The key thing which makes this 'modern' is the > '+' at the end of the command, rather than '\;'. > This causes find to execute the grep once per > group of files, rather than onc

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-11 Thread Alexander Gattin
Hello, On Thu, Feb 10, 2011 at 07:52:34AM +0100, Petter Gustad wrote: > r...@rpw3.org (Rob Warnock) writes: > > invocation was given only one arg!! IT FOUND > > THE PATTERN, BUT DIDN'T TELL ME WHAT > > !@^%!$@#@! FILE IT WAS IN!! :-{ > > Sounds frustrating, but

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-09 Thread Petter Gustad
r...@rpw3.org (Rob Warnock) writes: > invocation was given only one arg!! IT FOUND THE PATTERN, BUT DIDN'T > TELL ME WHAT !@^%!$@#@! FILE IT WAS IN!! :-{ Sounds frustrating, but grep -H will always print the filename, even when given a single filename on the command line. //Pett

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-09 Thread Thomas L. Shinnick
At 09:39 PM 2/9/2011, Rob Warnock wrote: Harald Hanche-Olsen wrote: [snip] Years & years ago, right after I learned about "xargs", I got burned several times on "find | xargs grep pat" when the file list was long enough that "xargs" fired up more than one

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-09 Thread Rob Warnock
Harald Hanche-Olsen wrote: +--- | [Icarus Sparry ] | > The 'modern' way to do this is | > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + | | Actually, I think it should be | find . -maxdepth 2 -name '*.html' -exec grep whatever /dev

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-09 Thread Rob Warnock
Harald Hanche-Olsen wrote: +--- | [Icarus Sparry ] | > The 'modern' way to do this is | > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + | | Actually, I think it should be | find . -maxdepth 2 -name '*.html' -exec grep whatever /

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-09 Thread Tassilo Horn
Xah Lee writes: >> You can rely on shell globbing, so that grep gets a list of all files in >> all subdirectories.  For example, I can grep all header files of the >> linux kernel using >> >>   % grep FOO /usr/src/linux/**/*.h > > say, i want to search in th

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-09 Thread Harald Hanche-Olsen
[Icarus Sparry ] > The 'modern' way to do this is > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + Actually, I think it should be find . -maxdepth 2 -name '*.html' -exec grep whatever /dev/null {} + \; because grep behaves differently when g

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-09 Thread Harald Hanche-Olsen
[Icarus Sparry ] > The 'modern' way to do this is > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + Actually, I think it should be find . -maxdepth 2 -name '*.html' -exec grep whatever /dev/null {} + because grep behaves differently when given onl

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-08 Thread Icarus Sparry
On Tue, 08 Feb 2011 14:30:53 -0800, Xah Lee wrote: > On Feb 8, 9:32 am, Icarus Sparry wrote: [snip] >> The 'modern' way to do this is >> find . -maxdepth 2 -name '*.html' -exec grep whatever {} + >> >> The key thing which makes this 'modern&#

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-08 Thread Xah Lee
On Feb 8, 9:32 am, Icarus Sparry wrote: > On Tue, 08 Feb 2011 13:51:54 +0100, Petter Gustad wrote: > > Xah Lee writes: > > >> problem with find xargs is that they spawn grep for each file, which > >> becomes too slow to be usable. > > > find . -maxdepth

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-08 Thread Petter Gustad
Icarus Sparry writes: > The 'modern' way to do this is > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + Agree, I've noticed that recent version of find have the + option. I remember in the old days the exec method was considered bad since it would fork

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-08 Thread Icarus Sparry
On Tue, 08 Feb 2011 13:51:54 +0100, Petter Gustad wrote: > Xah Lee writes: > >> problem with find xargs is that they spawn grep for each file, which >> becomes too slow to be usable. > > find . -maxdepth 2 -name '*.html -print0 | xargs -0 grep whatever >

Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-08 Thread Petter Gustad
Xah Lee writes: > problem with find xargs is that they spawn grep for each file, which > becomes too slow to be usable. find . -maxdepth 2 -name '*.html -print0 | xargs -0 grep whatever will call grep with a list of filenames given by find, only a single grep process will run.

Re: How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

2010-06-12 Thread Nobody
On Thu, 10 Jun 2010 08:40:03 -0700, Chris Seberino wrote: > On Jun 10, 6:52 am, Nobody wrote: >> Without the p1.stdout.close(), if the reader (grep) terminates before >> consuming all of its input, the writer (ls) won't terminate so long as >> Python retains the desc

Re: How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

2010-06-11 Thread Steven W. Orr
On 6/10/2010 11:40 AM, Chris Seberino wrote: Even if zombies are created, they will eventually get dealt with my OS w/o any user intervention needed right? Bad approach. Years ago I inherited a server that didn't do a proper cleanup pf its slaves. After a few days running, people discovered t

Re: grep command

2010-06-10 Thread rantingrick
On Jun 10, 7:56 am, "D'Arcy J.M. Cain" wrote: > On Thu, 10 Jun 2010 08:26:58 +0100 > I'm surprised that there is anyone left who hasn't killfiled this guy. > He/she hasn't made any effort to understand the group.  Why bother even > answering him?  Just filter him and enjoy the silence. All this

Re: How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

2010-06-10 Thread Dan Stromberg
On Thu, Jun 10, 2010 at 4:52 AM, Nobody wrote: > > Also, "ls | grep" may provide a useful tutorial for the subprocess module, > but if you actually need to enumerate files, use e.g. os.listdir/os.walk() > and re.search/fnmatch, or glob. Spawning child processes to perform ta

Re: How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

2010-06-10 Thread Lie Ryan
On 06/10/10 21:52, Nobody wrote: > Spawning child processes to perform tasks > which can easily be performed in Python is inefficient Not necessarily so, recently I wrote a script which takes a blink of an eye when I pipe through cat/grep to prefilter the lines before doing further c

Re: How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

2010-06-10 Thread Chris Seberino
On Jun 10, 6:52 am, Nobody wrote: > Without the p1.stdout.close(), if the reader (grep) terminates before > consuming all of its input, the writer (ls) won't terminate so long as > Python retains the descriptor corresponding to p1.stdout. In this > situation, the p1.wait() will

Re: How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

2010-06-10 Thread Grant Edwards
On 2010-06-10, Chris Seberino wrote: > How do subprocess.Popen("ls | grep foo", shell=True) with shell=False? You'll have to build your own pipeline with multiple calls to subprocess > Does complex commands with "|" in them mandate shell=True? Yes. Hey, I

Re: grep command

2010-06-10 Thread D'Arcy J.M. Cain
On Thu, 10 Jun 2010 08:26:58 +0100 Simon Brunning wrote: > On 10 June 2010 07:38, madhuri vio wrote: > > i was wondering bout the usage and syntax of > > grep command..can u tall me its syntax so that > > i can use it and proceed...pls > > That's really

Re: How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

2010-06-10 Thread Nobody
On Wed, 09 Jun 2010 21:15:48 -0700, Chris Seberino wrote: > How do subprocess.Popen("ls | grep foo", shell=True) with shell=False? The same way that the shell does it, e.g.: from subprocess import Popen, PIPE p1 = Popen("ls", stdout=PIPE) p2 = Popen(["gr

Re: grep command

2010-06-10 Thread Simon Brunning
On 10 June 2010 07:38, madhuri vio wrote: > > i was wondering bout the usage and syntax of > grep command..can u tall me its syntax so that > i can use it and proceed...pls That's really not on topic for this list. -- Cheers, Simon B. -- http://mail.python.org/mailman/listinfo/python-list

grep command

2010-06-09 Thread madhuri vio
i was wondering bout the usage and syntax of grep command..can u tall me its syntax so that i can use it and proceed...pls -- madhuri :) -- http://mail.python.org/mailman/listinfo/python-list

Re: How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

2010-06-09 Thread Chris Rebert
On Wed, Jun 9, 2010 at 9:15 PM, Chris Seberino wrote: > How do subprocess.Popen("ls | grep foo", shell=True) with shell=False? I would think: from subprocess import Popen, PIPE ls = Popen("ls", stdout=PIPE) grep = Popen(["grep", "foo"

How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

2010-06-09 Thread Chris Seberino
How do subprocess.Popen("ls | grep foo", shell=True) with shell=False? Does complex commands with "|" in them mandate shell=True? cs -- http://mail.python.org/mailman/listinfo/python-list

Re: python grep

2010-04-09 Thread Peter Otten
Mag Gam wrote: > I am in the process of reading a zipped file which is about 6gb. > > I would like to know if there is a command similar to grep in python > because I would like to emulate, -A -B option of GNU grep. > > Lets say I have this, > > 083828.441,AA > 09

Re: python grep

2010-04-08 Thread Stefan Behnel
Mag Gam, 08.04.2010 14:21: On Thu, Apr 8, 2010 at 7:31 AM, Stefan Behnel wrote: Mag Gam, 08.04.2010 13:21: I am in the process of reading a zipped file which is about 6gb. I would like to know if there is a command similar to grep in python because I would like to emulate, -A -B option of

Re: python grep

2010-04-08 Thread Mag Gam
t; >> I would like to know if there is a command similar to grep in python >> because I would like to emulate, -A -B option of GNU grep. >> >> Lets say I have this, >> >> 083828.441,AA >> 093828.441,AA >> 094028.441,AA >> 094058.441,CC >>

Re: python grep

2010-04-08 Thread Stefan Behnel
Mag Gam, 08.04.2010 13:21: I am in the process of reading a zipped file which is about 6gb. I would like to know if there is a command similar to grep in python because I would like to emulate, -A -B option of GNU grep. Lets say I have this, 083828.441,AA 093828.441,AA 094028.441,AA

python grep

2010-04-08 Thread Mag Gam
I am in the process of reading a zipped file which is about 6gb. I would like to know if there is a command similar to grep in python because I would like to emulate, -A -B option of GNU grep. Lets say I have this, 083828.441,AA 093828.441,AA 094028.441,AA 094058.441,CC 094828.441,AA 103828.441

Re: issue with grep command

2009-09-03 Thread Rhodri James
On Thu, 03 Sep 2009 19:51:20 +0100, Jul wrote: in tcsh terminal i have the following line of code cat fileName.txt | grep "a" which extracts all the instances of "a" from the file in the terminal.. however when i am trying to create a txt while, i am unable to do so for

Re: issue with grep command

2009-09-03 Thread Albert Hopkins
On Thu, 2009-09-03 at 11:51 -0700, Jul wrote: [Stuff about tcsh and grep deleted] What on earth does this have to do with Python? -a -- http://mail.python.org/mailman/listinfo/python-list

issue with grep command

2009-09-03 Thread Jul
in tcsh terminal i have the following line of code cat fileName.txt | grep "a" which extracts all the instances of "a" from the file in the terminal.. however when i am trying to create a txt while, i am unable to do so for some reason..this is the syntaxt i am using -- cat

Re: How should I use grep from python?

2009-05-07 Thread Nick Craig-Wood
Matthew Wilson wrote: > I'm writing a command-line application and I want to search through lots > of text files for a string. Instead of writing the python code to do > this, I want to use grep. > > This is the command I want to run: > > $ grep -l foo dir >

Re: How should I use grep from python?

2009-05-07 Thread Marco Mariani
Matthew Wilson wrote: consensus. I could os.popen, commands.getstatusoutput, the subprocess module, backticks, etc. Backticks do_not_do what you think they do. And with py3k they're also as dead as a dead parrot. -- http://mail.python.org/mailman/listinfo/python-list

Re: How should I use grep from python?

2009-05-07 Thread Matthew Wilson
On Thu 07 May 2009 09:25:52 AM EDT, Tim Chase wrote: > While it doesn't use grep or external processes, I'd just do it > in pure Python: Thanks for the code! I'm reluctant to take that approach for a few reasons: 1. Writing tests for that code seems like a fairly large am

Re: How should I use grep from python?

2009-05-07 Thread Matthew Wilson
On Thu 07 May 2009 09:09:53 AM EDT, Diez B. Roggisch wrote: > Matthew Wilson wrote: >> >> As of May 2009, what is the recommended way to run an external process >> like grep and capture STDOUT and the error code? > > subprocess. Which becomes pretty clear when readi

Re: How should I use grep from python?

2009-05-07 Thread Tim Chase
I'm writing a command-line application and I want to search through lots of text files for a string. Instead of writing the python code to do this, I want to use grep. This is the command I want to run: $ grep -l foo dir In other words, I want to list all files in the directory dir

Re: How should I use grep from python?

2009-05-07 Thread Diez B. Roggisch
Matthew Wilson wrote: > I'm writing a command-line application and I want to search through lots > of text files for a string. Instead of writing the python code to do > this, I want to use grep. > > This is the command I want to run: > > $ grep -l foo dir > >

How should I use grep from python?

2009-05-07 Thread Matthew Wilson
I'm writing a command-line application and I want to search through lots of text files for a string. Instead of writing the python code to do this, I want to use grep. This is the command I want to run: $ grep -l foo dir In other words, I want to list all files in the directory dir

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-03 Thread bearophileHUGS
Roy Smith: > But, along those lines, I've often thought that split() needed a way to not > just limit the number of splits, but to also throw away the extra stuff. > Getting the first N fields of a string is something I've done often enough > that refactoring the slicing operation right into the sp

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-03 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Peter Otten <[EMAIL PROTECTED]> wrote: > Roy Smith wrote: > > > In article <[EMAIL PROTECTED]>, > > Peter Otten <[EMAIL PROTECTED]> wrote: > > > >> > I might take it one step further, however, and do: > >> > > >> >> fields = line.split()[:2] > >> >>

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-03 Thread Peter Otten
Roy Smith wrote: > In article <[EMAIL PROTECTED]>, > Peter Otten <[EMAIL PROTECTED]> wrote: > >> > I might take it one step further, however, and do: >> > >> >> fields = line.split()[:2] >> >> a, b = map(int, fields) >> > >> > in fact, I might even get rid of the very generic,

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-03 Thread Roy Smith
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > Roy Smith: > > No reason to limit how many splits get done if you're > > explicitly going to slice the first two. > > You are probably right for this problem, because most lines are 2 > items long, but in scripts that have to process li

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-03 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Peter Otten <[EMAIL PROTECTED]> wrote: > > I might take it one step further, however, and do: > > > >> fields = line.split()[:2] > >> a, b = map(int, fields) > > > > in fact, I might even get rid of the very generic, but conceptually > > overkill,

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-03 Thread bearophileHUGS
Roy Smith: > No reason to limit how many splits get done if you're > explicitly going to slice the first two. You are probably right for this problem, because most lines are 2 items long, but in scripts that have to process lines potentially composed of many parts, setting a max number of parts sp

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-03 Thread Peter Otten
Roy Smith wrote: > In article <[EMAIL PROTECTED]>, > Peter Otten <[EMAIL PROTECTED]> wrote: > >> Without them it looks better: >> >> import sys >> for line in sys.stdin: >> try: >> a, b = map(int, line.split(None, 2)[:2]) >> except ValueError: >> pass >> else: >>

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-03 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Peter Otten <[EMAIL PROTECTED]> wrote: > Without them it looks better: > > import sys > for line in sys.stdin: > try: > a, b = map(int, line.split(None, 2)[:2]) > except ValueError: > pass > else: > if a + b == 42: >

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-03 Thread Peter Otten
hofer wrote: > Something I have to do very often is filtering / transforming line > based file contents and storing the result in an array or a > dictionary. > > Very often the functionallity exists already in form of a shell script > with sed / awk / grep , . . . > and I w

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-02 Thread Paul McGuire
ell script > with sed / awk / grep , . . . > and I would like to have the same implementation in my script > All that sed'ing, grep'ing and awk'ing, you might want to take a look at pyparsing. Here is a pyparsing take on your posted problem: from pyparsing import LineEnd,

Re: converting a sed / grep / awk / . . . bash pipe line into python

2008-09-02 Thread Marc 'BlackJack' Rintsch
On Tue, 02 Sep 2008 10:36:50 -0700, hofer wrote: > sed 's/\.\..*//' \### remove '//' comments | sed 's/#.*//' Comment does not match the code. Or vice versa. :-) Untested: from __future__ import with_statement from itertools import ifilter, ifilterfalse, imap def is_junk(line): line

converting a sed / grep / awk / . . . bash pipe line into python

2008-09-02 Thread hofer
Hi, Something I have to do very often is filtering / transforming line based file contents and storing the result in an array or a dictionary. Very often the functionallity exists already in form of a shell script with sed / awk / grep , . . . and I would like to have the same implementation in

Re: re.search much slower then grep on some regular expressions

2008-07-10 Thread Kris Kennaway
ot have this property. " Hmm, unfortunately it's still orders of magnitude slower than grep in my own application that involves matching lots of strings and regexps against large files (I killed it after 400 seconds, compared to 1.5 for grep), and that's leaving aside the much longer compi

Re: re.search much slower then grep on some regular expressions

2008-07-10 Thread Sebastian "lunar" Wiesner
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>: > On Mon, 07 Jul 2008 16:44:22 +0200, Sebastian \"lunar\" Wiesner wrote: > >> Mark Wooding <[EMAIL PROTECTED]>: >> >>> Sebastian "lunar" Wiesner <[EMAIL PROTECTED]> wrote: >>> # perl -e '("a" x 10) =~ /^(ab?)*$/;' zsh: segmentation fau

  1   2   3   >