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.

https://github.com/hyakuhei/csv-split

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

example.csv
Id, IP, Team, Info
1, 10.1.1.1, Ops, Operations Team
2, 10.1.1.2, Ops, Operations Jump-Off Box
3, 10.1.1.3, Admin, Admin Team
4, 10.1.1.4, Admin, Admin Management Server
5, 192.168.1.1, Web, Load Balancer
6, 192.168.1.2, Web, Load Balancer
7, 172.0.0.1, Wibble, Application Server
8, 172.0.0.1, Wibble, Application Montor

Running the following will create 4 files, Ops.csv, Admin.csv, Web.csv, Wibble.csv
$ python csvsplit.py --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.


https://github.com/hyakuhei/csv-split

No comments:

Post a Comment