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
GRUB-MKIMAGE(1) 						   User Commands						   GRUB-MKIMAGE(1)

NAME
grub-mkimage - make a bootable image of GRUB SYNOPSIS
grub-mkimage [OPTION...] [OPTION]... [MODULES] DESCRIPTION
Make a bootable image of GRUB. -c, --config=FILE embed FILE as an early config -C, --compression=(xz|none|auto) choose the compression to use for core image -d, --directory=DIR use images and modules under DIR [default=/usr/lib/grub/<platform>] -k, --pubkey=FILE embed FILE as public key for signature checking -m, --memdisk=FILE embed FILE as a memdisk image Implies `-p (memdisk)/boot/grub' and overrides any prefix supplied previously, but the prefix itself can be overridden by later options -n, --note add NOTE segment for CHRP IEEE1275 -o, --output=FILE output a generated image to FILE [default=stdout] -O, --format=FORMAT generate an image in FORMAT available formats: i386-coreboot, i386-multiboot, i386-pc, i386-pc-pxe, i386-pc-eltorito, i386-efi, i386-ieee1275, i386-qemu, x86_64-efi, i386-xen, x86_64-xen, mipsel-yeeloong-flash, mipsel-fuloong2f-flash, mipsel-loongson-elf, pow- erpc-ieee1275, sparc64-ieee1275-raw, sparc64-ieee1275-cdcore, sparc64-ieee1275-aout, ia64-efi, mips-arc, mipsel-arc, mipsel-qemu_mips-elf, mips-qemu_mips-flash, mipsel-qemu_mips-flash, mips-qemu_mips-elf, arm-uboot, arm-efi, arm64-efi -p, --prefix=DIR set prefix directory -v, --verbose print verbose messages. -?, --help give this help list --usage give a short usage message -V, --version print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options. REPORTING BUGS
Report bugs to <bug-grub@gnu.org>. SEE ALSO
grub-install(8), grub-mkrescue(1), grub-mknetdir(8) The full documentation for grub-mkimage is maintained as a Texinfo manual. If the info and grub-mkimage programs are properly installed at your site, the command info grub-mkimage should give you access to the complete manual. grub-mkimage (GRUB) 2.02-2ubuntu8.3 July 2018 GRUB-MKIMAGE(1)
All times are GMT -4. The time now is 05:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy