#!/usr/bin/env python # Note that this script does not handle variables with apostrophes in # them; it assumes that variables will always be quoted with apostrophes # Convert a file like this, suitable for use with a shell like bash: # export TZ='PST8PDT' #export HTTP_HOST='esmf.ess.uci.edu' #export HTTP_USER_AGENT='Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.0.7-1.1.fc4 Firefox/1.0.7' #export HTTP_ACCEPT='text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' #export HTTP_ACCEPT_LANGUAGE='en-us,en;q=0.5 HTTP_ACCEPT_ENCODING=gzip,deflate' #export HTTP_ACCEPT_CHARSET='ISO-8859-1,utf-8;q=0.7,*;q=0.7' #export HTTP_KEEP_ALIVE='300' #export HTTP_CONNECTION='keep-alive' #export HTTP_PRAGMA='no-cache' #export HTTP_CACHE_CONTROL='no-cache' #export PATH=/bin:/usr/bin:/usr/local/bin #export SERVER_SIGNATURE='
Apache/2.0.55 (Unix) Server at esmf.ess.uci.edu Port 80 #' #export SERVER_SOFTWARE='Apache/2.0.55 (Unix)' #export SERVER_NAME='esmf.ess.uci.edu' #export SERVER_ADDR='128.200.197.165' #export SERVER_PORT='80' #export REMOTE_ADDR='128.200.34.70' #export DOCUMENT_ROOT='/usr/local/apache-2.0.55/htdocs' #export SERVER_ADMIN='you@example.com' #export SCRIPT_FILENAME='/usr/local/apache-2.0.55/cgi-bin/dods/nph-dods' #export REMOTE_PORT='56803' #export GATEWAY_INTERFACE='CGI/1.1' #export SERVER_PROTOCOL='HTTP/1.1' #export REQUEST_METHOD='GET' #export QUERY_STRING='' #export REQUEST_URI='/cgi-bin/dods/nph-dods/dodsdata/in.nc.html' #export SCRIPT_NAME='/cgi-bin/dods/nph-dods' #export PATH_INFO='/dodsdata/in.nc.html' #export PATH_TRANSLATED='/usr/local/apache-2.0.55/htdocs/dodsdata/in.nc.html' #export BASH_ENV='' #export JGOFS_OBJECT='`pwd`' #export JGOFS_METHOD='`pwd`' # into this, suitable for use with env-search: #64 #2 #TZ #7 #PST8PDT #9 #HTTP_HOST #16 #esmf.ess.uci.edu #15 #HTTP_USER_AGENT #100 #Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.0.7-1.1.fc4 Firefox/1.0.7 #11 #HTTP_ACCEPT #99 #text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 #20 #HTTP_ACCEPT_LANGUAGE #48 #en-us,en;q=0.5 HTTP_ACCEPT_ENCODING=gzip,deflate #19 #HTTP_ACCEPT_CHARSET #30 #ISO-8859-1,utf-8;q=0.7,*;q=0.7 #15 #HTTP_KEEP_ALIVE #3 #300 #15 #HTTP_CONNECTION #10 #keep-alive #11 #HTTP_COOKIE #78 #ucinetid_auth=lfLgbD28sTKkRAucZyMbMqlyB0KXhfkslVynprmIbWSSncUdBxfdNqBfhb2ohdHt #11 #HTTP_PRAGMA #8 #no-cache #18 #HTTP_CACHE_CONTROL #8 #no-cache #16 #SERVER_SIGNATURE #75 #Apache/2.0.55 (Unix) Server at esmf.ess.uci.edu Port 80 # #15 #SERVER_SOFTWARE #20 #Apache/2.0.55 (Unix) #11 #SERVER_NAME #16 #esmf.ess.uci.edu #11 #SERVER_ADDR #15 #128.200.197.165 #11 #SERVER_PORT #2 #80 #11 #REMOTE_ADDR #13 #128.200.34.70 #13 #DOCUMENT_ROOT #31 #/usr/local/apache-2.0.55/htdocs #12 #SERVER_ADMIN #15 #you@example.com #15 #SCRIPT_FILENAME #46 #/usr/local/apache-2.0.55/cgi-bin/dods/nph-dods #11 #REMOTE_PORT #5 #56803 #17 #GATEWAY_INTERFACE #7 #CGI/1.1 #15 #SERVER_PROTOCOL #8 #HTTP/1.1 #14 #REQUEST_METHOD #3 #GET #12 #QUERY_STRING #0 # #11 #REQUEST_URI #42 #/cgi-bin/dods/nph-dods/dodsdata/in.nc.html #11 #SCRIPT_NAME #22 #/cgi-bin/dods/nph-dods #9 #PATH_INFO #20 #/dodsdata/in.nc.html #15 #PATH_TRANSLATED #51 #/usr/local/apache-2.0.55/htdocs/dodsdata/in.nc.html #8 #BASH_ENV #0 # #12 #JGOFS_OBJECT #5 #`pwd` #12 #JGOFS_METHOD #5 #`pwd` # In short, the env-search format is: # Number of variables # Number of characters in variable name # Characters of variable name # Number oif characters in variable value # Characters of variable value # Number of characters in variable name # Characters of variable name # Number oif characters in variable value # Characters of variable value import sys import string import re initial_pattern = re.compile("export \w\w*='[^']*'", re.MULTILINE | re.DOTALL) refinement_pattern = re.compile("^.*export (\w\w*)='([^']*)'", re.MULTILINE | re.DOTALL) content = sys.stdin.read() #print content all_exports = re.findall(initial_pattern, content) #print all_matches print len(all_exports) for export in all_exports: refinement = refinement_pattern.match(export) # print refinement.group(0) # print refinement.group(1) # print refinement.group(2) print len(refinement.group(1)) print refinement.group(1) print len(refinement.group(2)) print refinement.group(2)