Link to home
Start Free TrialLog in
Avatar of richsark
richsarkFlag for United States of America

asked on

add a syntax to a csv file

Hi folks,

I need a way to to read a file that's in csv format ( keeping in mind the header)  like so:

Country	View	Zone	Zone_Sort	Type	Storage	AD-Domain	Servers	NS	MastersForwarders	Region
		0.117.176.in-addr.arpa	arpa.in-addr.176.117.0	master	db.0.117.176.in-addr.arpa					
		0.134.208.in-addr.arpa	arpa.in-addr.208.134.0	master	db.0.134.208.in-addr.arpa					

Open in new window


The file can be 1,000 of lines long, the above is just a snipit

I would a way to for the file to be read and spit out an output called "compiled-zones-script.pl"

the contents would look like:

named-compilezone -i none -k ignore -j -o ../compile_zones/db.0.117.176.in-addr.arpa 0.117.176.in-addr.arpa db.0.117.176.in-addr.arpa
named-compilezone -i none -k ignore -j -o ../compile_zones/db.0.134.208.in-addr.arpa 0.134.208.in-addr.arpa db.0.134.208.in-addr.arpa

Open in new window


Instead of using concatenate in excel, can this be done in perl script or shell script where I can execute the file assuming that the compile_zones directory is there :) or maybe have the script create it.

Thanks in advance
Avatar of Maciej S
Maciej S
Flag of Poland image

grep "in-addr.arpa" file.csv| while read zone sort type storage; do
echo named-compilezone -i none -k ignore -j -o ../compile_zones/${storage} ${zone} ${storate}
done > compiled-zones-script.pl

Open in new window

Avatar of richsark

ASKER

hello oklit, so I can take the above and make a file named compile_zone.sh

or what you provided is a copy paste in a term window in my mac
also, I ended up with commas ,,, after I ran it.. see below

named-compilezone -i none -k ignore -j -o ../compile_zones/ ,,0.218.195.in-addr.arpa,arpa.in-addr.195.218.0,master,db.0.218.195.in-addr.arpa,,,,,

Open in new window


can we get those out please.
Please post your exact csv file (part of it of course). The one you posted in your question didn't have any commas.
HI, attached... The file could be tab sep or ,, ( comma ) so we need to account for it please.
Workbook5.csv
ASKER CERTIFIED SOLUTION
Avatar of Maciej S
Maciej S
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice. Thank you !

would I need to post a separate ? to make this a perl script or a shell script?

Thanks again!
Unfortunately I can't help you with perl.
You can leave these question opened and wait for perl solution, or you can open new one (in that case don't add 'shell scripting' category and write in your question that you are interested in perl solution only).