Normal text file into csv

Microsoft Windows xp professional w/serv...
September 10, 2010 at 04:36:25
Specs: Windows XP, 512
I have a normal text file which is a output of firewall status:-

Firewall enabled: Yes
Exceptions disabled: No
Notifications disabled: No
Unicast responses to multicast broadcast disabled: No


i want to change the above file into csv format so that i can export into some databse
a desired format is:-

Node Firewall enabled Exception enabled Notfication Unicast responses to multicast

hostname yes No No No
or ipadd

any suggesstions in this regard is greatly appreciated

thanks in advance



See More: Normal text file into csv

Report •


#1
September 10, 2010 at 05:12:43
download gawk for windows then save the below as myscript.awk


BEGIN{
 FS=":"
 print "Node,Firewall enabled,Exception enabled,Notfication,Unicast responses to multicast"
 cmd="hostname"
 cmd | getline hostname
 printf "%s",hostname
}
{ s=s","$2 }
END{ print s }

on command line

C:\test>gawk.exe -f myscript.awk file
Node,Firewall enabled,Exception enabled,Notfication,Unicast responses to multicast
rtxglb8, Yes, No, No, No

GNU win32 packages | Gawk


Report •

#2
September 13, 2010 at 02:10:09
thanks for ur suggestion......... but the outpt file when i got after conversion to csv after running C:\test>gawk.exe -f myscript.awk file >output.csv
is as follows

Node,Firewall enabled,Exception disabled,Notfication disabled,Unicast responses
conf6xp,,,, Yes, No, No, No
i.e there is about 3 commas extra after hostname .how to remove these 3 commas so that i get correct algnment.

thanks in advnce



Report •

#3
September 13, 2010 at 02:37:18
how does your input file look like? As you can see from my output using the sample you gave, i do not have a problem with extra commas.

GNU win32 packages | Gawk


Report •

Related Solutions

#4
September 13, 2010 at 02:50:47
Firewall 1.1 - Windows Firewall Configuration Utility
Copyright (C) 2009-2010 by Greg Wittmeyer - All Rights Reserved

Firewall enabled: Yes
Exceptions disabled: No
Notifications disabled: No
Unicast responses to multicast broadcast disabled: No

---------------------------------------------------------------------------------------------------

this is the input file i used.........

thanks in advance


Report •

#5
September 13, 2010 at 03:17:38
your latest input file differs from the original , of course there must be something not right. You do not really want the first 3 lines, so skip them
BEGIN{
 FS=":"
 print "Node,Firewall enabled,Exception enabled,Notfication,Unicast responses to multicast"
 cmd="hostname"
 cmd | getline hostname
 printf "%s",hostname
}
NR>3{ s=s","$2 }
END{ print s }


GNU win32 packages | Gawk


Report •

#6
September 13, 2010 at 03:29:22
sorry it was my mistake..............

any way !!!!!!!!!!!!!!! checked the new script/////////// it is working fine....

thank u very much for your advice.......


Report •


Ask Question