Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 22nd, 2008, 07:47 PM
AndrewG1976 AndrewG1976 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Melbourne, Australia
Posts: 42 AndrewG1976 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 12 m 13 sec
Reputation Power: 5
Extract name/value pairs from text file into csv

Hi,

I need to extract the parameters from an input file (ini) and put them into a spreadsheet (output file) for reporting and analysis. My requirement is:

Input file: parameters.ini (text)

[SECTION 1]

Name1 = 'value1'
Name2 = 'value2'

[SECTION 2]

Name3 = 'value3'
Name3 = 'value4'


Output file: parameters.csv (text/csv)

SECTION1, Name1, value1
SECTION1, Name2, value2
SECTION2, Name3, value3
SECTION2, Name4, value4


Does anyone know how to do this in a batch file (preferred) or shell script?

Thanks,
Andrew

Reply With Quote
  #2  
Old May 23rd, 2008, 09:45 AM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,278 bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 15 h 17 m 35 sec
Reputation Power: 309
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
Quote:
Originally Posted by AndrewG1976
Hi,

I need to extract the parameters from an input file (ini) and put them into a spreadsheet (output file) for reporting and analysis. My requirement is:

Input file: parameters.ini (text)

[SECTION 1]

Name1 = 'value1'
Name2 = 'value2'

[SECTION 2]

Name3 = 'value3'
Name3 = 'value4'


Output file: parameters.csv (text/csv)

SECTION1, Name1, value1
SECTION1, Name2, value2
SECTION2, Name3, value3
SECTION2, Name4, value4


Does anyone know how to do this in a batch file (preferred) or shell script?

Thanks,
Andrew


One idea would be to define a variable whose value initially is SECTION1.

As you progress through the lines, each time you find one that matches the pattern NAMEx=y, then output a line that has the value of the variable followed by a colon followed by NAMEx followed by a colon followed by y

Then each time you find a line that matches the pattern [SECTIONx], you can change the value of the variable.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Extract name/value pairs from text file into csv


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT