To read data word by word from given file & storing in variables

File having data in following format :
file name : file.txt
--------------------
111111;name1
222222;name2
333333;name3

I want to read this file so that I can split these into two paramaters i.e. 111111 & name1 into two different variables(say value1 & value2).

i.e val1=11111 & val2=name1...& so on....

In between these two parameters semicolon is there ..

Can anybody help me to write a shell script for this ?

Hi,

look for "awk", "cut" in man pages or in the forum, there is a lot of similar problems solved.

For something simply formatted like this you can change your IFS (internal field separator) to whatever is separating your values and then loop through it. By default the IFS is a space " ", but in this case it's a ";". So you can do the following:

(12:25:08\[D@DeCoBox15)
[~]$ cat test
111111;name1
222222;name2
333333;name3

(12:26:43\[D@DeCoBox15)
[~]$ IFS=";";while read value name;do echo "Value is $value and name is $name";done < test
Value is 111111 and name is name1
Value is 222222 and name is name2
Value is 333333 and name is name3

What's even more fun (and I've only recently started to understand) is putting everything into an array and then call it from there:

(12:29:50\[D@DeCoBox15)
[~]$ IFS=";";while read line;do line=($line);echo "name is "${line[0]}" value is "${line[1]}"";done < test
name is 111111 value is name1
name is 222222 value is name2
name is 333333 value is name3