2 Replies - 330 Views - Last Post: 23 August 2011 - 06:20 PM Rate Topic: -----

#1 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Another regex module question.

Posted 20 August 2011 - 12:53 PM

I know I've been blowing up the board the past two days, and if you guys want me to piss off, just say so. I'm just trying to get this project done before school starts (Monday). Anyway, an example output for this command looks like:
+ CC=gcc
+ C_LINKPATH_SHL=
+ WRAPPER_CFLAGS='-m64 -O2 -fPIC'
+ WRAPPER_LDFLAGS='-Wl,-z,noexecstack '
+ MPILIBNAME=mpich
+ PMPILIBNAME=pmpich
+ MPI_OTHERLIBS=' -lpthread   -lrt   '
+ NEEDSPLIB=no
+ MPICH2_VERSION=1.2.1p1
+ Show=
+ '[' -n '' ']'
+ '[' -n '' ']'
+ linking=yes
+ allargs=("$@")
+ argno=0
+ for arg in '"$@"'
+ addarg=yes
+ case "$arg" in
+ '[' yes = no ']'
++ expr 0 + 1
+ argno=1
+ '[' 1 -eq 0 ']'
+ '[' no = yes ']'
+ mpilibs='-lmpich -lopa'
+ CFLAGS='-m64 -O2 -fPIC'
+ LDFLAGS='-Wl,-z,noexecstack '
+ '[' -n '' ']'
+ '[' yes = yes ']'
+ '[' -n '' ']'
+ gcc -m64 -O2 -fPIC -Wl,-z,noexecstack mpiworld.c -I/usr/include/mpich2-x86_64 -L/usr/lib64/mpich2/lib -L/usr/lib64/mpich2/lib -lmpich -lopa -lpthread -lrt
+ rc=0
+ exit 0



I am looking for a way to isolate the words with -l in front of them, i.e. -lmpich, -lopa, -lpthread, etc. My first crack at a pattern looks like this:

found = re.search('\b-l.\b',line)



but this doesn't return anything. What gives?

Is This A Good Question/Topic? 0
  • +

Replies To: Another regex module question.

#2 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Re: Another regex module question.

Posted 20 August 2011 - 01:44 PM

OK, so I've got something going here:
   found = re.findall('-l[a-z]{1,9}\s',line)



returns this:
['-lpthread  ', '-lrt  ']
['-lmpich ', "-lopa'\n"]
['-lmpich ', '-lopa ', '-lpthread ', '-lrt\n']



and I know how to go through and remove the -l and the \n, which I need to do, but a follow up question is: Is it possible to skip over repeat instances within this method? Or should I just do that as I output / transfer the data?
Was This Post Helpful? 0
  • +
  • -

#3 Python_4_President  Icon User is offline

  • D.I.C Regular

Reputation: 53
  • View blog
  • Posts: 321
  • Joined: 13-August 11

Re: Another regex module question.

Posted 23 August 2011 - 06:20 PM

May the force you with be.

multi_line_output = <that output you posted with each line as an element in a list or file iterable>

unique_commands = set([re.search("-l\S*", line) for line in multi_line_output])


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1