Visit the LQ Articles and Editorials section
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-28-2004, 05:24 AM   #1
LQ Newbie
Registered: Mar 2004
Posts: 1

Rep: Reputation: 0
Reading data from file (field organizzation)

hi folk,
I'm a
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
Old 03-29-2004, 06:03 AM   #2
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,371

Rep: Reputation: 192Reputation: 192
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading audio data files as an actual audio file? Erik_the_Red Linux - Software 1 06-01-2005 08:22 AM
What is the data type field definition to save RTF file? Linux4BC Linux - General 3 06-02-2004 05:19 AM
Reading comma-separated data from file MeLassen Programming 4 04-04-2004 03:41 PM
reading data from a file afrm Programming 2 12-16-2003 08:43 PM
Reading COM Port Data croakofonix Programming 1 06-11-2003 05:17 PM

All times are GMT -5. The time now is 07:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration