Delimited Text Parsing Script (perl)



By: nathanshaw

December 8, 2011 12:46 pm

Reads: 480

License:
Free for all

Download csvparser.pl

This is a very simple PERL script that may be quite useful when working with delimited text files, especially for those of you who write/maintain Delimited Text drivers in IDM. You can use it in a few different ways:

  • Convert a file from one delimiter to another
  • Parse a file to make sure each field has quotes around it (instead of only those with spaces)
  • Recreate your file but only specific columns
  • Recreate your file with the columns in any order you want
  • All of the above combined

If you’re good with the Linux command line tools, combine this script with grep, sed, awk, wc, etc. to do all sorts of things. I wrote it so that I could quickly look through a large CSV file I get from our HR system and return only the fields I want. For example, using this script and other built in tools I can quickly figure out how many active employees we have within a specific business unit without having to load the CSV into a database and query it that way.

The script was written for Linux, but seems to work in Windows too (tested using Active Perl base installation).

CSV Parser v1.0.2 - Parse data from a delimited text file.

Usage: csvparser.pl -c [file]

Required:
   -c | --csv [File]            Specify a CSV with the input data

Options:
   -i | --inputdelim [char]     Input file delimiter (Default: ",")
   -o | --outputdelim [char]    Output using different delimiter (Default: ",")
   -f | --fields [#,#,#,#]      Fields to print (base 0) - Order will be maintained. (Default: All)
   -q | --quotes                Include quotes around the fields (Default: Off)
   -h | --help                  Help!
   -d | --deubg                 Enable debugging info
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags: , , , , ,
Categories: Cool Tools, Identity Manager

Disclaimer: As with everything else at NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment.  It just worked for at least one person, and perhaps it will be useful for you too.  Be sure to test in a non-production environment.

Comment