Sponsored Content
Top Forums Shell Programming and Scripting regular expression grouping across multiple lines Post 302706461 by chirish on Wednesday 26th of September 2012 08:20:35 PM
Old 09-26-2012
duh..

Code:
>>> f = open('book.txt', 'r')
>>> text = f.read()
>>> f.close()
>>> m = re.findall(r'(book\d).+?price\s(\d+)', text, re.DOTALL)
>>> m
[('book1', '23'), ('book2', '22'), ('book3', '24'), ('book4', '25'), ('book5', '13')]

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

regular expression across some lines

I am trying to use regular expression to identify ONLY the commands that hasn't the word "tablespace" within it. a command starts with "create table" and ends with ; (semicolon) example file: create table first tablespace ; create table second ( BBL_CUSTOMER_NAME VARCHAR2(32), a... (7 Replies)
Discussion started by: ynixon
7 Replies

2. Shell Programming and Scripting

regular expression grepping lines with VARIOUS number of blanks

Hi, I need a regular expression grepping all lines starting with '*' followed by a VARIOUS number of blanks and then followed by the string 'Runjob=1'. I tried that code, but it doesn't work: grep -i '*'+'Runjob=1' INPUT_FILE >>OUTPUT_FILE Can someone help me? Thanks (8 Replies)
Discussion started by: ABE2202
8 Replies

3. Shell Programming and Scripting

sed not printing lines before a regular expression.

Hey, I found a way to print the lines which is just before a regular expression, not including the expression. sed -n '/regexp/{n;p;}' myfile Now I'm looking for a way to print all lines, exept the regular expression and also the line before the same regular expression. Use code tags. (1 Reply)
Discussion started by: Livio
1 Replies

4. Shell Programming and Scripting

Would like to print 3 lines after a regular expression is found in the logfile

I would like to print 3 lines after a regular expression is found in the logfile. I'm using the following code: grep -n "$reg_exp" file.txt |while read LINE ;do i=$(echo $LINE |cut -d':' -f1 ) ;sed -n "$i,$(($i+3))p" file.txt ;done The above code things works fine,but sometimes gives erroneous... (3 Replies)
Discussion started by: joachimshaun
3 Replies

5. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

6. UNIX for Dummies Questions & Answers

delete lines matching a regular expression

I have a very large file (over 700 million lines) that has some lines that I need to delete. An example of 5 lines of the file: HS4_80:8:2303:19153:193032 153 k80:138891 HS4_80:8:2105:5544:43174 89 k88:81949 165 k88:81949 323 0 * = 323 0 ... (6 Replies)
Discussion started by: pathunkathunk
6 Replies

7. UNIX for Dummies Questions & Answers

Finding lines with a regular expression, replacing them with blank lines

So the tag for this forum says all newbies welcome... All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed. Here's what I did come up with though: ... (2 Replies)
Discussion started by: Golpette
2 Replies

8. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

9. Shell Programming and Scripting

Regular expression to match multiple lines?

Using a regular expression, I would like multiple lines to be matched. By default, a period (.) matches any character except newline. However, (?s) and /s modifiers are supposed to force . to accept a newline and to match any character including a newline. However, the following two perl... (4 Replies)
Discussion started by: LessNux
4 Replies

10. Shell Programming and Scripting

BASH - Regular Expressions :Looking for one word on multiple lines.

Im looking for a bash solution that will use Regular Expressions (not perl, sed or awk) to check the example data below and then give me a status. which would be just simply Match or Mismatch. SYS PS1 is present. Fan status: Normal Input Voltage status: Normal ... (5 Replies)
Discussion started by: popeye
5 Replies
OCONV(1)						      General Commands Manual							  OCONV(1)

NAME
oconv - create an octree from a RADIANCE scene description SYNOPSIS
oconv [ -i octree | -b xmin ymin zmin size ][ -n objlim ][ -r maxres ][ -f ][ -w ][ - ] [ input .. ] DESCRIPTION
Oconv adds each scene description input to octree and sends the result to the standard output. Each input can be either a file name, or a command (enclosed in quotes and preceded by a `!'). Similarly, the octree input may be given as a command preceded by a `!'. If any of the surfaces will not fit in octree, an error message is printed and the program aborts. If no octree is given, a new one is created large enough for all of the surfaces. The -b option allows the user to give a bounding cube for the scene, starting at xmin ymin zmin and having a side length size. If the cube does not contain all of the surfaces, an error results. The -b and -i options are mutually exclusive. The -n option specifies the maximum surface set size for each voxel. Larger numbers result in quicker octree generation, but potentially slower rendering. Smaller values may or may not produce faster renderings, since the default number (6) is close to optimal for most scenes. The -r option specifies the maximum octree resolution. This should be greater than or equal to the ratio of the largest and smallest dimensions in the scene (ie. surface size or distance between surfaces). The default is 16384. The -f option produces a frozen octree containing all the scene information. Normally, only a reference to the scene files is stored in the octree, and changes to those files may invalidate the result. The freeze option is useful when the octree file's integrity and loading speed is more important than its size, or when the octree is to be relocated to another directory, and is especially useful for creating library objects for the "instance" primitive type. If the input octree is frozen, the output will be also. The -w option suppresses warnings. A hyphen by itself ('-') tells oconv to read scene data from its standard input. This also implies the -f option. The only scene file changes that do not require octree regeneration are modifications to non-surface parameters. If the coordinates of a surface are changed, or any primitives are added or deleted, oconv must be run again. Programs will abort with a "stale octree" message if they detect any dangerous inconsistencies between the octree and the input files. Although the octree file format is binary, it is meant to be portable between machines. The only limitation is that machines with radi- cally different integer sizes will not work together. For the best results, the -f option should be used if an octree is to be used in different environments. DIAGNOSTICS
There are four basic error types reported by oconv: warning - a non-fatal input-related error fatal - an unrecoverable input-related error system - a system-related error internal - a fatal error related to program limitations consistency - a program-caused error Most errors are self-explanatory. However, the following internal errors should be mentioned: Too many scene files Reduce the number of scene files by combining them or using calls to xform(1) within files to create a hierarchy. Set overflow in addobject (id) This error occurs when too many surfaces are close together in a scene. Either too many surfaces are lying right on top of each other, or the bounding cube is inflated from an oversized object or an improper -b specification. If hundreds of triangles come together at a common vertex, it may not be possible to create an octree from the object. This happens most often when inane CAD systems create spheres using a polar tessellation. Chances are, the surface "id" is near one of those causing the problem. Hash table overflow in fullnode This error is caused by too many surfaces. If it is possible to create an octree for the scene at all, it will have to be done in stages using the -i option. EXAMPLE
To add book1, book2 and a transformed book3 to the octree ``scene.oct'': oconv -i scene.oct book1 book2 '!xform -rz 30 book3' > newscene.oct AUTHOR
Greg Ward NOTES
In the octree, the names of the scene files are stored rather than the scene information. This means that a new octree must be generated whenever the scene files are changed or moved. Also, an octree that has been moved to a new directory will not be able to find scene files with relative pathnames. The freeze option avoids these problems. make(1) or rad(1) can be used to automate octree creation and mainte- nance. SEE ALSO
getbbox(1), getinfo(1), make(1), obj2mesh(1), rad(1), rpict(1), rvu(1), rtrace(1), xform(1) RADIANCE
8/15/95 OCONV(1)
All times are GMT -4. The time now is 10:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy