Sponsored Content
Top Forums Programming Python re.findall inverse Match Post 302965626 by durden_tyler on Monday 1st of February 2016 10:34:35 AM
Old 02-01-2016
Quote:
Originally Posted by metallica1973
...I am used to using "!" or boolean "not" but have never done it using Pythons "re" module. ...
Yes, Python uses the more verbose "not" instead of "!" for negative regex matches.

Code:
$
$ cat pkg_list.txt
'zssh (1.5c.debian.1-3.2+b1 [s390x], 1.5c.debian.1-3.2 [amd64, arm64, armel, armhf, i386, mips, mipsel, powerpc, ppc64el])',
'zsync (0.6.2-1)',
'zzuf (0.13.svn20100215-4.1+b1 [s390x], 0.13.svn20100215-4.1 [amd64, arm64, armel, armhf, i386, mips, mipsel, powerpc, ppc64el])']
'ztex-bmp (20120314-2)',
$
$ cat -n negative_match.py
     1  #!/usr/bin/python
     2  import re
     3  input_file = "pkg_list.txt"
     4  for line in open(input_file):
     5      if not re.match('.*\[s390x\].*', line):
     6          print line,
     7
$
$ python negative_match.py
'zsync (0.6.2-1)',
'ztex-bmp (20120314-2)',
$
$

For reference, here's the corresponding regex in Perl:

Code:
$
$ perl -lne 'print if !/\[s390x\]/' pkg_list.txt
'zsync (0.6.2-1)',
'ztex-bmp (20120314-2)',
$
$ perl -lne 'print if not /\[s390x\]/' pkg_list.txt
'zsync (0.6.2-1)',
'ztex-bmp (20120314-2)',
$
$

This User Gave Thanks to durden_tyler For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Inverse Video

I am trying to discover the sequence of escape characters that I need to pass ksh in order to turn inverse video on and off. I need this information for two reasons: * I want to include inverse video text in some shell scripts * I wish to highlight a section of an /etc/motd file Thanks for... (2 Replies)
Discussion started by: sam_pointer
2 Replies

2. Shell Programming and Scripting

matrix inverse (awk)

I need to inverse a matrix given in a file. The problem is I'm stuck with writing determinant finding algoritm into code. I found this algoritm about finding determinant of nxn matrix. This is what i need: Matrices and Determinants and here: a11 a12 a13 a21 a22 a23 a31 a32 a33... (0 Replies)
Discussion started by: vesyyr
0 Replies

3. Shell Programming and Scripting

use python or awk to match names 'with error tolerance'

I think this is a very challenging problem I am facing and I have no idea how to deal with it Suppose I have two csv files A.csv Toyota Camry,1998,blue Honda Civic,1999,blue B.csv Toyota Inc. Camry, 2000km Honda Corp Civic,1500km I want to generate C.csv Toyota Camry,1998,blue... (7 Replies)
Discussion started by: grossgermany
7 Replies

4. Shell Programming and Scripting

Inverse of Cut

Hi List, I have a CSV file which I am manipulating. Each time I receive the CSV for processing, there will be extra columns of data. Here's what I want to do; I want to be able to remove specific columns from the CSV data file, but keep the remaining columns, where the remaining columns are... (3 Replies)
Discussion started by: landossa
3 Replies

5. Shell Programming and Scripting

Inverse Grep

Hi, I'm trying to wtite a script which actually print the text which doesn't contain a word , i mean to say. eg:- if a file contains the follwoing data Hello how ru ??? What ru doing ? what is the % of data contained ??? I want to write a script such that it prints the line excluding... (1 Reply)
Discussion started by: nagios
1 Replies

6. Shell Programming and Scripting

sed one Liner inverse range match-help required

cat test.txt a c d e g (2 Replies)
Discussion started by: TomG
2 Replies

7. Shell Programming and Scripting

Python fails to detect String Match Found

Below is my code for comparing string for Exact Match found in python. for word in jdbc_trgt.split(','): global comp comp=word.strip(); print "GloBAL:" + comp fiIn = open('list.txt').readlines() for lines in fiIn: print "line1s:" +... (6 Replies)
Discussion started by: mohtashims
6 Replies

8. Shell Programming and Scripting

Python etree.ElementTree findall function

Hi everyone. I'm trying to learn python as it relates to parsing xml, and I thought I would start by trying to create an easy (or I thought would be easy) function to match on a certain attribute in an xml file and print out it's related attribute. Here's an example to hopeful make sense of... (0 Replies)
Discussion started by: timj123
0 Replies

9. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
TRANSITION-CHECK(1)													       TRANSITION-CHECK(1)

NAME
transition-check - check a package list for involvement in transitions SYNOPSIS
transition-check --help|--version transition-check [-f|--filename=FILENAME] [source package list] DESCRIPTION
transition-check checks whether any of the listed source packages are involved in a transition for which uploads to unstable are currently blocked. If neither a filename nor a list of packages is supplied, transition-check will use the source package name from debian/control. OPTIONS
-f, --filename=filename Read a source package name from filename, which should be a Debian package control file or .changes file, and add that package to the list of packages to check. EXIT STATUS
The exit status indicates whether any of the packages examined were found to be involved in a transition. 0 Either --help or --version was used, or none of the packages examined was involved in a transition. 1 At least one package examined is involved in a current transition. LICENSE
This code is copyright by Adam D. Barratt <adam@adam-barratt.org.uk>, all rights reserved. This program comes with ABSOLUTELY NO WARRANTY. You are free to redistribute this code under the terms of the GNU General Public License, version 2 or later. AUTHOR
Adam D. Barratt <adam@adam-barratt.org.uk> Debian Utilities 2013-12-23 TRANSITION-CHECK(1)
All times are GMT -4. The time now is 07:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy