Problem reading into Variable using KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem reading into Variable using KSH
# 1  
Old 09-13-2010
Problem reading into Variable using KSH

hi all,
i create 1 file.txt and inside it contain :
file1
file2
file3
file 4

then output that i want in my script:
Code:
$1=file1
$2=file2
$3=file3
$4=file4

but,when write in ksh script with:
Code:
while read folder
set - $( echo ${folder} )
  i=1
  while (($i <= $#))
          do
            eval echo var$i=\$$i

done<file.txt

the output i get :
Code:
$1=file1
$1=file2
$1=file3

Anybody can help me solve it?
Thx

---------- Post updated at 03:49 PM ---------- Previous update was at 03:45 PM ----------

hi sonu,
i new user at this forum..can i now where i create my own post?
thx

Last edited by pludi; 09-13-2010 at 04:54 AM..
# 2  
Old 09-13-2010
Hi.

Your code doesn't work at all. And some of it is not clear. Like, what has folder, etc. have to do with it?

And it's not so clear if you mean $1 or var$1.

Code:
$ cat Args
while read LINE
do
  set -- $@ "$LINE"
done < file.txt

echo var1 is $1
echo var2 is $2
echo var3 is $3
echo var4 is $4

$ ./Args
var1 is file1
var2 is file2
var3 is file3
var4 is file 4

# 3  
Old 09-13-2010
that script i write in KSH shell script.
while the script i write actually is get the data inside file.txt and assign it as variable.
Code:
var1=file1
var2=file2
var3=file4

but the output for my script is :
Code:
var1=file1
var1=file2
var1=file3

this is script i write :

while read folder:
Code:
set - $( echo ${folder} )
  i=1
  while (($i <= $#))
          do
            eval echo\"\ var$i=\$$i\"

done<file.txt


Last edited by Scott; 09-13-2010 at 06:02 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading file and exclude in ksh

I have a text file containing some file names. And I've a directory containing files with different name. I want to do some operaration (deleting) on the files which are NOT listed on the text file. Im using KSH. PLEASE HELP !!!!! Urgent Help!!!!! (2 Replies)
Discussion started by: maheshbabu
2 Replies

2. Shell Programming and Scripting

Reading xml tags from ksh script

Hi, I have an XMl file, below is sample: <TRANSFORMATION DESCRIPTION ="Created by:- " NAME ="LKP_FT_T_FILEK" OBJECTVERSION ="1" REUSABLE ="YES" TYPE ="Lookup Procedure" VERSIONNUMBER ="1"> </TRANSFORMATION> I need to read the tag, and if the tag is TRANSORMATION, i want to check the Type... (6 Replies)
Discussion started by: kedar_laveti
6 Replies

3. Shell Programming and Scripting

Reading the contents of the file and splitting using ksh

We're using a ksh script for installing one product. I've another config file, I'd need to read this configuration file from my main script Content of the Configuration file:... (2 Replies)
Discussion started by: bittu129
2 Replies

4. Shell Programming and Scripting

reading value of concatenation with ksh

hello all, I am trying to read the value of a concatenation, the following code is displaying $word1 $word2 I want to display village home Thanks for (( i=1; i<=2; i++ )) do word1='village' word2='home' con="$"word"$i" echo $con done (5 Replies)
Discussion started by: wydadi
5 Replies

5. Shell Programming and Scripting

Problem with KSH script using scalar variable

Hi Guys, I'm having a hard time bringing out my desired output from my korn shell script. This particular statement from my script its seems not working perl -ne 'print if $_ lt ${date1}' . My complete script as shown below. Please help. Code: #!/usr/bin/ksh ... (5 Replies)
Discussion started by: victorneri
5 Replies

6. Shell Programming and Scripting

Reading variable from file variable values

Hi, Here is the output of lpstat. I would like to read value of Queue which is(abxxxxb1)and status that is DOWN in first line. i dont care what is in second line. any one can help me.thanks Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- ---------... (5 Replies)
Discussion started by: sagii
5 Replies

7. Shell Programming and Scripting

reading from file in ksh

hi, it seems i can read using cat file | while read line but when i tried reading using while read line < myfile then the last line kept on being returned why? thanks (2 Replies)
Discussion started by: JamesByars
2 Replies

8. Shell Programming and Scripting

reading lines in pairs from file in ksh

I need to read pairs of lines from a file and compare them. We can assume that the number of lines in the file is even. Can i do it in korn shell? (4 Replies)
Discussion started by: ytokar
4 Replies

9. Shell Programming and Scripting

Help reading an input file in KSH

First I' d like to say you guys are awesome. :) I have a word document that I cut and paste into Textpad and it removed all the fancy formatting which is fine with me. I WinScp'd it to the box and and called it inputfile.txt. Opened it in vi and don't see any special characters or stuff that... (2 Replies)
Discussion started by: zilla30066
2 Replies

10. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies
Login or Register to Ask a Question