Tool

nathanshaw's picture
tool
Reads:

4901

Score:
2.666665
2.7
6
 
Comments:

0

Delimited Text Parsing Script (perl)

(View Disclaimer)

license: 
Free for all

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
AttachmentSize
csvparser.pl.txt6.53 KB

Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).

It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.




User Comments

© 2013 Novell