Retrieve data from a file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Retrieve data from a file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-28-2008
tpltp tpltp is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 8 July 2012, 11:25 PM EDT
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Retrieve data from a file

Hello guys

I want to retrieve two data from a file, like this:
bash-2.03$ cat numtest
123456
123457
bash-2.03$ more ./test_num
#!/bin/bash
num1=
num2=
cnt=1

while read x
do
num${cnt}=$x
cnt=$(($cnt+1))
done <$1
echo $num1 "\n" $num2

But when i executed this script, error popped up
bash-2.03$ ./test_num numtest
./test_num: num1=123456: command not found
./test_num: num2=123457: command not found
\n

Can anyone give any suggestion? Thank you.
Sponsored Links
    #2  
Old 03-28-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 22 August 2014, 8:27 AM EDT
Location: /dev/ph
Posts: 4,784
Thanks: 63
Thanked 424 Times in 393 Posts
eval is your friend


Code:
while read x
do
  eval num${cnt}=${x}
  cnt=$(($cnt + 1))
done < $1

Sponsored Links
    #3  
Old 03-28-2008
tpltp tpltp is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 8 July 2012, 11:25 PM EDT
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
I will rememer this friend from now on. thank you for introducing him to me.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to compare two columns and retrieve data bjorngill UNIX for Dummies Questions & Answers 7 07-27-2011 11:05 AM
More time to retrieve data from DB pattamuthu Shell Programming and Scripting 4 07-14-2011 02:03 AM
How to retrieve data using awk command prasad4004 Shell Programming and Scripting 5 07-30-2010 04:08 AM
Retrieve data and redirect to a file anupdas UNIX for Advanced & Expert Users 2 01-18-2010 12:42 AM
to find header in Mp3 file and retrieve data shashi Programming 2 09-12-2008 03:03 AM



All times are GMT -4. The time now is 01:40 PM.