Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with variables...

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
US
Hey all... I have a CSV file which has the following lines: (about 6k entries...)

Joe Smith,joe@foofoo.com,3333,,

Trying to parse each line and insert the $1,$2,$4 fields into:
[3333]
type=friend
username=Joe Smith
host=dynamic
secret=3333
context=gateway
callerid="Joe Smith"<2125551212>
nat=no
call-limit=1000"


while read list.csv
do
name=`awk '{print $1,$2}' list.csv`
ext=`awk '{ gsub(/,/, " ");print $4} list.csv`
awk '{print "[$ext]\ntype=friend\nusername="$ext"\nhost=dynamic\nsecret="$ext"\ncontext=gateway\ncallerid="$name"<2125551212>\nnat=no\ncall-limit=1000\n"}' list.csv
done

-bash: read: `list.csv': not a valid identifier

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
Hi

Code:
awk -F, '{print "["$3"]\ntype=friend\nusername="$1"\nhost=dynamic\nsecret="$3"\ncontext=gateway\ncallerid=\""$1"\"<2125551212>\nnat=no\ncall-limit=1000\n"}' /input/file

Feherke.
 
Thanks feherke worked like a charm... I didn't know I could have parsed out the fields without actually separating it (, " ") ... I learn something new everyday.

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top