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
zsyncmake(1)							   File Transfer						      zsyncmake(1)

NAME
zsyncmake - Build control file for zsync(1) SYNTAX
zsyncmake [ { -z | -Z } ] [ -e ] [ -C ] [ -u url ] [ -U url ] [ -b blocksize ] [ -o outfile ] [ -f targetfilename ] [ -v ] filename zsync -V DESCRIPTION
Constructs a metafile for the zsync client program to use to perform partial file downloads. filename is the file that users wish to down- loads; zsyncmake constructs the appropriate metafile and writes filename.zsync in the current directory. zsync will need at least one URL from which to download the file content. If the .zsync will be in the same directory as the file to down- load, you can accept the default - zsync includes a relative URL in the control file. If not, use the -u option to specify the URL. You should also specify a URL for the uncompressed content with -U if available, as zsync can make use of this for more efficient downloads sometimes. (You can edit the .zsync file and add these afterwards - it has a simple key: value format in the header - but I suggest you only do this once you are familiar with the tool.) Note that zsyncmake itself does not (currently) verify the URLs or download any data, you must provide the file data locally and check the URLs yourself. OPTIONS
-b blocksize Specify the blocksize to the underlying rsync algorithm. A smaller blocksize may be more efficient for files where there are likely to be lots of small, scattered changes between downloads; a larger blocksize is more efficient for files with fewer or less scat- tered changes. This blocksize must be a power of two. If not specified, zsyncmake chooses one which it thinks is best for this file (currently either 2048 or 4096 depending on file size) - so normally tyou should not need to override the default. -C Tells zsyncmake not to generate any instructions in the .zsync telling the client to compress the data it receives. This is implied by -z, but this option is here in case you compress a file yourself only for the transfer, but want the client to end up with the uncompressed file (e.g. you are transferring an ISO, which is held compressed on the server, but which the client cannot use unless it is uncompressed). Without -C, zsyncmake will produce directions for the client to compress the file it receives where appropri- ate; -C is here so you can stop it telling the client to do that. -e Tells zsyncmake that the client must be able to receive the exact file that was supplied. Without this option, zsyncmake only gives a weaker guarantee - that the client will receive the data it contains (e.g. it might transfer the uncompressed version of a .gz to the client). Note that this still doesn't guarantee that the client will get it - the client could ignore the directives in the zsync file, or might be incapable of exactly reproducing the compression used. But with -e you know that zsyncmake has made it pos- sible to get the exact data - it will exit with an error if it cannot. -f filename Set the filename to include in the output file (this is what the file will be called when a user finished downloading it). -o outputfile Override the default output file name. -u url Specifies the URL from which users can download the content of the supplied file. Users need the control file in order to find out what parts of the file they already have, and they need the URLs to retrieve the parts of the file that they don't already have. You can specify multiple URLs by specifying -u multiple times. If not specified, zsync assumes that the file and the .zsync will reside in the same public directory, and includes a single relative URL. -U url Specifies a URL corresponding to the decompressed content of the file (only applicable if it is a gzip file). zsync can sometimes download more efficiently from the uncompressed data than from the compressed data - it will take advantage of this if available. If no URLs are specifies, zsync looks for a file without the .gz extension and assumes that this will be in the same public dir as the .zsync, and includes a relative URL to it. -v Enable verbose messages. -V Prints the version of zsync. -z Compress the file to transfer. Note that this overwrites any file called filename.gz without warning (if you don't give a filename, e.g. because you are reading from stdin, then zsync will use the name supplied with -f, or as a last fallback, zsync-target.gz). zsync can work with compressed data, and, in most cases where the data is not already compressed, it is more efficient to compress it first. While you can just compress the file to transfer with gzip, if you use this option then zsyncmake will compress the file for you, producing a .gz file which is optimised for zsync. This can be 30% more efficient at download time than compressing with gzip --best - but the compressed file will not be as small at that produced by gzip. -Z zsyncmake automatically looks inside gzip compressed files and exports the underlying, uncompressed data to the zsyncmake file. In testing this has proved to provide greater download efficiency. -Z overrides the default behaviour and treats gzip files as just binary data. Use this if it is essential that the user receives the compressed data (for instance because a cryptographic signature is available only for the compressed data). zsync is typically no use if you specify -Z, unless the gzip file was compressed with the special --rsync option to make it friendly to differential transfers. EXAMPLES
zsyncmake -C -u http://ftp.uk.debian.org/debian/dists/sarge/main/binary-i386/Packages.gz Packages.gz Note use of -C to save the client compressing the file on receipt; the Debian package system uses the file uncompressed. zsyncmake -z my-subversion-dump In this case there is a large, compressible file to transfer. This creates a gzipped version of the file (optimised for zsync), and a .zsync file. A URL is automatically added assuming that the two files will be served from the same directory on the web server. zsyncmake -e -u http://www.mirrorservice.org/sites/ftp.freebsd.org/pub/FreeBSD/ports/distfiles/zsync-0.2.2.tar.gz zsync-0.2.2.tar.gz This creates a zsync referring to the named source tarball, which the client should download from the given URL. This example is for down- loading a source tarball for a FreeBSD port, hence -e is specified so the client will be able to match its md5sum. AUTHORS
Colin Phipps <cph@moria.org.uk> SEE ALSO
zsync(1) Colin Phipps 0.6.2 zsyncmake(1)
All times are GMT -4. The time now is 05:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy