[Tutor] IP address parse
I'm trying to parse a log file for all ip addresses but can't get my RE to work. Thanks in advance for pointing me in the right direction #IP address parse ## import re infile = open(host0_declare.txt,r) outfile = open(out.txt,w) patt = re.compile(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3}) for line in infile: m = patt.match(line) if m: outfile.write(%s.%s.%s.%s\n%m.groups()) infile.close() outfile.close() # ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Simple copy script
This is what I came up with after writing it out and reading the corresponding functions. I feel I'm close but something is still awry. #file copy based on input file containing filenames to be copied ## import os import shutil os.chdir('c:\\test') infile = open(input.txt,r) for line in infile: shutil.copy(line, 'outfolder') #print line 'copied' infile.close() # -- Forwarded message -- From: Alan Gauld [EMAIL PROTECTED] Date: Sat, Apr 12, 2008 at 5:15 AM Subject: Re: [Tutor] Simple copy script To: tutor@python.org Que Prime [EMAIL PROTECTED] wrote I'm trying to copy files from one directory to another based on an input txt file containing the filename. Source directory = C:\test Destination directory = C:\output input.txt looks like: 12345.pdf 12344.pdf Try writing what you want to do in structured English first Open the file input.txt For each line in input.txt : copy the named file from source to destination Close the file input.txt Now can you write that ion Python? (You may want to check the shutil module for copying the files) If you can';t get it to work send us your code and any error messages you get. You will find more detailed info in the Using the OS topic of my tutor. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Simple copy script
I'm trying to copy files from one directory to another based on an input txt file containing the filename. Source directory = C:\test Destination directory = C:\output input.txt looks like: 12345.pdf 12344.pdf I having trouble getting my mind around a loop that would accomplish this. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Copy script
I have a folder of 150,000 pdf files and I need to copy 20,000 of them to another folder. The ones I need to copy are in a .txt file. Attached is a sample of the input .txt file and a dos directory of the folder containing the files. I'm not sure of the best way to accomplish this. Thank you in advance for your help. Sample input file: 12347424 12347425 12347426 12347427 Sample dir on folder: 03/20/2008 09:21 AM 145,257 00011479 [7ac0c741-9d2f-4a1d-9dbf-8de27ca0abb4].pdf 03/20/2008 09:21 AM 154,655 00011600 [cd752a5a-388a-4bad-9a52-fb3711f685b8].pdf 03/20/2008 09:21 AM 145,556 00015234 [4344f5ff-fa58-4e20-bf27-697c71a81fbc].pdf 03/20/2008 09:21 AM 152,785 12347424 [44cc0d43-a80d-4415-8e92-b6a4f62986b4].pdf 03/20/2008 09:21 AM 145,551 12347425 [0ea7b60a-3631-4f64-91fa-6e385296f18f].pdf Volume in drive C has no label. Volume Serial Number is 0873-E099 Directory of C:\Documents and Settings\test 04/09/2008 03:57 PMDIR . 04/09/2008 03:57 PMDIR .. 03/20/2008 09:21 AM 145,647 0737 [f05d4dcc-8c0e-4660-b9f7-83708dfc782e].pdf 03/20/2008 09:21 AM 144,945 1237 [b951dfd8-af0e-4243-9951-0cf63b7f5f1a].pdf 03/20/2008 09:21 AM 145,984 1491 [7a9d5843-55d7-4a37-9903-a210ff538d12].pdf 03/20/2008 09:21 AM 145,644 1777 [dd9b13cc-f088-4957-a2df-a9dac2959e81].pdf 03/20/2008 09:21 AM 145,730 1995 [cb12e1ef-074a-4b41-abfc-6aa2048d5008].pdf 03/20/2008 09:21 AM 149,319 2609 [dc64fabf-fe2f-47bf-90a4-f1eef43586d6].pdf 03/20/2008 09:21 AM 145,994 2789 [b7242dd2-cfa9-435c-a8f7-05d9d500dbcc].pdf 03/20/2008 09:21 AM 145,788 4169 [9ed9f002-12e2-4a7a-952e-2d2a5a44b775].pdf 03/20/2008 09:21 AM 152,189 4247 [18b05f77-d429-4231-8e99-541e07613e3a].pdf 03/20/2008 09:21 AM 161,951 8623 [decd3cb9-c6bf-4d17-9bdd-cb1d63023aeb].pdf 03/20/2008 09:21 AM 147,243 00010957 [1ae26ed1-8114-49ab-9eeb-40f636ffd257].pdf 03/20/2008 09:21 AM 145,257 00011479 [7ac0c741-9d2f-4a1d-9dbf-8de27ca0abb4].pdf 03/20/2008 09:21 AM 154,655 00011600 [cd752a5a-388a-4bad-9a52-fb3711f685b8].pdf 03/20/2008 09:21 AM 145,556 00015234 [4344f5ff-fa58-4e20-bf27-697c71a81fbc].pdf 03/20/2008 09:21 AM 152,785 12347424 [44cc0d43-a80d-4415-8e92-b6a4f62986b4].pdf 03/20/2008 09:21 AM 145,551 12347425 [0ea7b60a-3631-4f64-91fa-6e385296f18f].pdf 04/09/2008 03:57 PM 0 dir.txt 17 File(s) 2,374,238 bytes 2 Dir(s) 39,714,271,232 bytes free 12347424 12347425 12347426 12347427 12347428 12347429 12347430 12347431 12347432 12347433 12347434 12347435 12347437 12347438 12347439 12347440 12347442 12347443 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Regular Expression
I need to pull the highligted data from a similar file and can't seem to get my script to work: Script: import re infile = open(filter.txt,r) outfile = open(out.txt,w) patt = re.compile(r~02([\d{10}])) for line in infile: m = patt.match(line) if m: outfile.write(%s\n) infile.close() outfile.close() File: 200~02001491~05070 200~02001777~05070 200~02001995~05090 200~02002609~05090 200~02002789~05070 200~012~02004169~0 200~02004247~05090 200~02008623~05090 200~02010957~05090 200~02 011479~05090 200~0199~02001237~ 200~02011600~05090 200~012~02 022305~0 200~02023546~05090 200~02025427~05090 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Parsing several files
With the help of a tutor I was able to get the following code to work the way I want, but I'd like for it to parse through several files in one folder and create one output file. I'm thinking I need to add something like: def grab_files(files = []): found = [] if files != None: Here is the original: import re infile = open(in.txt,r) outfile = open(out.txt,w) patt = re.compile(r'.*src=([\d\.]*) dst=(10.52.10.10.*)') for line in infile: m = patt.match(line) if m: outfile.write('src=%s dst=%s\n' % m.groups()) infile.close() outfile.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] gendata.py
This script appears to be written for Unix systems. Is there a way to get it to work for PythonWin? from random import randint, choice from string import lowercase from sys import maxint from time import ctime doms = ( 'com', 'edu', 'net', 'org', 'gov' ) for i in range(randint(5, 10)): dtint = randint(0, maxint-1)#pick date dtstr = ctime(dtint)#date string shorter = randint(4,7) #login shorter em = '' for j in range(shorter):#generate login em += choice(lowercase) longer = randint(shorter, 12) #domain longer dn = '' for j in range(longer): #create domain dn += choice(lowercase) print '%s::[EMAIL PROTECTED]::%d-%d-%d' % (dtstr, em, dn, choice(doms), dtint, shorter, longer) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] File parse
I'm trying to parse a file and extract 'src=172.16.148.27 dst=10.52.10.10' out of each line that contains 10.52.10.10, but get lost with writing the information and am not sure if I should .re at all. import re infile = open(in.txt,r) outfile = open(out.txt, w) for line in infile: re.match('src=*10.52.10.10') outfile.write(re.compile) ofile.close() wfile.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] String or Re
I'm working on the following code to read a log file and output lines containing '10.52.10.10' but am unsure of whether to use a regular expression or string to achive this. Can someone please enlighten me? Thank you. infile = open(in.txt,r) outfile = open(out.txt, w) for line in infile: if line #contains '10.52.10.10': outfile.write(line) ofile.close() wfile.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Question
I'm trying to create a program that creates a file and write the number for each line. Here is what I have so far but can't seem to get the loop and write correct. Thanks in advance. print Creating txt file tfile = open(25.txt, w) for i in range(25): x = int(1) tfile.writelines(x\n) x += 1 tfile.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor