Computing.Net > Forums > Unix > Read file and assign to variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Read file and assign to variables

Reply to Message Icon

Name: ahteck
Date: July 1, 2003 at 03:35:46 Pacific
OS: AIX UNIX
CPU/Ram: 512
Comment:

Hi,
My file list.txt look like this:-

abc.model 09 10 12:01 cad usr1 /tmp/users
xyz.model 11 03 10:00 cam usr2 /tmp/test

How can I read the file and assign the variable to each of them as:-
var1=abc.model
var2=09
var3=10
var4=12:01
var5=cad
var6=usr1
var7=/tmp/users

So that I can do thing like:-
while read str
do
cp var7/var1 /tmp
done list.txt

Thanks
ahteck



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: July 1, 2003 at 04:10:51 Pacific
Reply:

cat list.txt | while read var1 var2 var3 var4 var5 var6 var7 ; do
cp ${var7}/${$var1} /tmp
done


0

Response Number 2
Name: ahteck
Date: July 2, 2003 at 18:26:34 Pacific
Reply:

Yes! It works!

Thanks
ahteck


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Read file and assign to variables

Shell script to get the files by range www.computing.net/answers/unix/shell-script-to-get-the-files-by-range/8413.html

Read file and replace..shell script www.computing.net/answers/unix/read-file-and-replaceshell-script/5083.html

how to find files and move to direc www.computing.net/answers/unix/how-to-find-files-and-move-to-direc/4822.html