-   Programming (
-   -   Reading data from file (field organizzation) (

eiem 03-28-2004 04:24 AM

Reading data from file (field organizzation)
hi folk,
I'm a :newbie:
first of all , excuse me for my english, it's not my natural language :P

than, we go stright on my problem:

for my firewall I want to make some configuration files like:


4 example prerouting.cong:

#IP_machine PORT

#my pc 6000 12000

#production 2 21000 11023

And than, I want my rc.firewall like this:



# Prerouting service #


cat $FILECONF | awk '!/#/&&/\y/ {

`$iptables -t nat -A PREROUTING -p tcp --dport $2 -i ppp0 -j DNAT --to $1:$2`


I use "!/#/&&/\y/" to delete the "#" line and blank line
the ` command ` isn't accept from awk construct :(

I can use :

awk '......{



but so I can't use variables in "command" neither internal variables (awk var) nor external (x ex.: $ANY or $iptables)...

So, I try to use the "for" loop like this

for HOST in " 6000" " 12000"
set -- $HOST
$iptables -t nat -A PREROUTING -p tcp --dport $2 -i ppp0 -j DNAT --to $1:$2
#during first loop, $1= and $2=6000 and so on...

It work fine good, but I don't know how to make,reading from file, an array made like this:

each field of array is made of a list of 2( or n..) elements: "IP PORT"

$HOSTLIST=(" 6000" ....

It dosen't work!


At the end of all, I don't know how to solve my problem: read 2 field data from a conf file!!!!
Anyone have some suggestions??!?!?!?!?

TNX... (even only for attantion!!! :P)

Alex, IT

bigearsbilly 03-29-2004 05:03 AM

i not sure i understand, but
if data file is:


address port
if you read into multiple variables it will split the line
into them for you, like "read a b c d e"
then do something like:


cat file | while read address port;do
  echo address=$address
  echo port=$port

All times are GMT -5. The time now is 09:30 AM.