Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Retrieve data from a file

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 03-28-2008
fpmurphy's Unix or Linux Image
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 12 June 2016, 11:03 PM EDT
Location: /dev/ph
Posts: 4,996
Thanks: 73
Thanked 475 Times in 437 Posts
eval is your friend


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

Sponsored Links
    #3  
Old Unix and Linux 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 12:05 PM
More time to retrieve data from DB pattamuthu Shell Programming and Scripting 4 07-14-2011 03:03 AM
How to retrieve data using awk command prasad4004 Shell Programming and Scripting 5 07-30-2010 05:08 AM
Retrieve data and redirect to a file anupdas UNIX for Advanced & Expert Users 2 01-18-2010 01:42 AM
to find header in Mp3 file and retrieve data shashi Programming 2 09-12-2008 04:03 AM



All times are GMT -4. The time now is 08:18 PM.