parsed.org

Tips by tag: parsing

Change Field Separator in Data by cygnus on Jan 12, 2005 10:27 AM

You can use awk to change the field separator in a data stream:

$ cat foo
a,b,c,d,e,f
a,b,c,d,e,f
$ awk 'BEGIN { FS = ","; OFS = ".."; } { $1 = $1; print }' foo
a..b..c..d..e..f
a..b..c..d..e..f

(You just have to touch one of the fields to get it to process the line.)

awkcommandsfieldsparsingshell
Path Calculation by xinu on Mar 30, 2007 01:13 PM

If you need to tell a python framework where your templates, etc. are located, it helps to determine the location of the current module.

BASE_PATH = os.path.abspath(os.path.join(os.path.dirname(__FILE__), '..'))
TEMPLATES = os.path.join(BASE_PATH, 'templates')

Assuming you're running this code in /path/to/module.py, BASE_PATH will be set to /path. Other os.path tricks can be used to dynamically set paths in this way.

locationosparsingpathpython
Pipe Read by xinu on Jan 25, 2005 02:01 PM

If you want the time, and only the time:

$ date | (read u v w x y z; echo $x)
14:05:52
commandsdateextrasparsingshell
RSS