Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone01.am1.xlned.com!bcyclone01.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:text': 0.05; 'subject:file': 0.07; 'subject:help': 0.08; 'level:': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'python': 0.11; 'expressions.': 0.16; 'url:re': 0.16; 'wrote:': 0.18; '(where': 0.19; 'thanks.': 0.20; 'header:User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; 'received:(smtp server)': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'extract': 0.31; 'gary': 0.31; 'file': 0.32; 'regular': 0.32; 'text': 0.33; 'url:python': 0.33; 'subject:with': 0.35; 'done,': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'level': 0.37; 'represent': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'url:3': 0.61; 'charset:windows-1252': 0.65; 'sample': 0.67; 'on...': 0.68; 'useful.': 0.68; 'score': 0.74; 'irrelevant': 0.84; 'round,': 0.91 X-Virus-Scanned: OK X-Sender-Id: gary.herron@islandtraining.com Date: Thu, 04 Dec 2014 20:54:15 -0800 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: help with processing text file References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417755628 news.xs4all.nl 2852 [2001:888:2000:d::a6]:57294 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3485 X-Received-Body-CRC: 3406521591 Xref: csiph.com comp.lang.python:81973 On 12/04/2014 08:46 PM, C. Ng wrote: > Hi, > > Given the sample text file below (where the gibberish represent the irrelevant portions) : > > .... > abcddsdfffgfg > ggfhghghgfhghgh round 5 xccdcxcfd > sdfdffdfbcvcvbbvnghg score = 0.4533 > abcddsdfffgfg round 5 level = 0.15 > ggfhghghgfhghgh round 10 dfsdfdcdsd > sdfdffdfbcvcvbbvnghg score = 0.4213 > sdsdaawddddsds round 10 level = 0.13 > ......and so on.... > > > I would like to extract the values for round, score and level: > 5 0.4533 0.15 > 10 0.4213 0.13 > ....and so on... > > Please advise me how it can be done, and what Python functions are useful. > > Thanks. I would use regular expressions. See https://docs.python.org/3/library/re.html Gary Herron