I use an application called Easy-IP to keep track of IP utilization. Underneath lies a Firebird database, which I've extracted to CSV. The header line lists all the columns, but I wanted to know the array index for processing. Short of counting commas, I came up with:
head -1 ./current.csv |perl -ane '$i = 0; s/\,/" ".$i++."\n"/eg; print
+;'
The header line looks like so:
SUBNET_ID,AUTONOMOUS_NETWORK_ID,PARENT_ID,TREE_PATH,SUBNET,CIDR_MASK,I
+P_VERSION,LOW_ADDRESS,HIGH_ADDRESS,BROADCAST_ADDRESS,SHORT_SUBNET,ASS
+IGNED_ADDRESSES,CHILD_SUBNET_COUNT,COMMENT,SYSTEM_FLAG1,REPLICATED_FR
+OM,CREATED,UPDATED,LOCATION,USAGE,NETWORK_NAME,IP_NETWORK,IP_NETWORK_
+BLOCK,ORGANIZATION,ADMIN_CONTACT,TECH_CONTACT,ORG_NAME,STREET_ADDRESS
+,CITY,STATE,POSTAL_CODE,COUNTRY_CODE,PRIMARY_SERVER,SECONDARY_SERVER
My output, abbreviated:
SUBNET_ID 0
AUTONOMOUS_NETWORK_ID 1
PARENT_ID 2
TREE_PATH 3
SUBNET 4
...
I bet the brains at PM can do better. Suggestions?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.