parsing a config file using bash

Hi ,

I have a config _file that has 3 columns (Id Name Value ) with many rows . In my bash script i want to be able to parse the file and do a mapping of any Id value
so if i have Id of say brand1 then i can use the name (server5X) and Value (CCCC) and so on ...

Id Name Value
brand1 server5X CCCC
vbn hhhh tyiowq
we yyyu yyyooooooo
12BB das_12 eqwr12
--
--
--
I was something like so which is not working .

#!/bin/bash
IFS=,
while read var1 var2 var3
do
echo "$var1 , $var2, $var3 
done < "config_file"

if the file is delimited by the comma (,) then only you need to use IFS=,

otherwise the below is enough

 
while read var1 var2 var3
do
echo "$var1 , $var2, $var3"
done < config_file

#!/bin/bash
IFS=" "
while read var1 var2 var3
do
echo "$var1 , $var2, $var3 "
done < "config_file"

Separating on spaces rather than commas and closing the quotes around the echoed string resolved here

1 Like