Thursday, 2 May 2013

Split up CSV based on field contents

Had a requirement to create lots of little CSV files based on a particular field within one CSV file.

This script allows you to choose a field to pivot on, take this example data:

Id, IP, Team, Info
1,, Ops, Operations Team
2,, Ops, Operations Jump-Off Box
3,, Admin, Admin Team
4,, Admin, Admin Management Server
5,, Web, Load Balancer
6,, Web, Load Balancer
7,, Wibble, Application Server
8,, Wibble, Application Montor

Running the following will create 4 files, Ops.csv, Admin.csv, Web.csv, Wibble.csv
$ python --infile example.csv --field Team

This is really handy for handling csv output from a bunch of tools, such as Nessus, Nexpose, Nessus and many others.

No comments:

Post a Comment