Retrieve multiple values for each iteration


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retrieve multiple values for each iteration
# 1  
Old 03-18-2012
Retrieve multiple values for each iteration

Hi All,

I tried to retrieve multiple values using for/foreach loop in each iteration. But couldn't get it. Please help me.
Below are my try outs:
Code:
#!/bin/ksh
foreach {i,j,k} {5150 5540 5149 5640 5151 5920 5362 5965 5147 5895 5061}
  echo $i,$j,$k
end

Error:
Code:
./mulcns.ksh[3]: foreach:  not found
,,
./mulcns.ksh[5]: end:  not found

Code:
#!/bin/ksh
for {i,j,k} in {5150 5540 5149 5640 5151 5920 5362 5965 5147 5895 5061}
do
echo $i $j $k
done

Error:
./mulcns.ksh[2]: {x,y,z}: is not an identifier
</code>

Last edited by Franklin52; 03-19-2012 at 04:17 AM.. Reason: Fixed code tags
# 2  
Old 03-18-2012
foreach is used in csh not ksh.

for {i,j,k} in {5150 5540 5149 5640 5151 5920 5362 5965 5147 5895 5061} is not proper Korn shell syntax for a for loop construct. Please read the man page.
# 3  
Old 03-19-2012
Hi Frank,

Thanks for your reply.
The syntax is
for var in list
But I just had a try to get multiple values at a time
If you know pls reply. ThanksSmilie
# 4  
Old 03-19-2012
form three values for each line, then use while to retrieve the values

Code:
 
while read a b c
do
echo $a
echo $b
echo $c
done < in.txt

make sure you have three values in each line in the in.txt file
# 5  
Old 03-19-2012
Thanks KamarajSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Edit and replace the multiple values in a file in one iteration

Hi All, I am preserving OLD and NEW values and want to replace the values in one go instead of using multiple sed and mv commands. Please help. echo "\nEnter the new qStart time '${CODE}' - (Hit Enter for No Change): \c" read NEW echo "\nEnter the new qStop time '${CODE}' - (Hit Enter for... (2 Replies)
Discussion started by: sdosanjh
2 Replies

2. Shell Programming and Scripting

How to retrieve values from XML file and update them in the same position! PLEASE HELP?

Good Day All Im quiet new to ksh scripting and need a bit of your help. I am attempting to write a script that reads in an XML and extracts certain field values from an XML file. The values are all alphanumeric and consist of two components: e.g "Test 1". I need to to create a script that... (2 Replies)
Discussion started by: JulioAmerica
2 Replies

3. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

4. Shell Programming and Scripting

Retrieve multiple rows from mysql and automatically create a table

Hi, i want to create a table automatically based on another table (sms_key). For example; If user create a new row with sms_keyword field: IRC then a table created automatically (with some field on it, like: name, ph_number, messages). select * from sms_key; +-------------+ |... (1 Reply)
Discussion started by: jazzyzha
1 Replies

5. Programming

Sctp api name to retrieve the values of structure sctpassoctable

Hi i want a sctp (lksctp) api which can retrieve the values of the sctp structure "sctpAssocTable" It is sctpassoctable or sctpassocentry. SctpAssocEntry ::= SEQUENCE { sctpAssocId Unsigned32, sctpAssocRemHostName OCTET STRING, sctpAssocLocalPort ... (1 Reply)
Discussion started by: harioum
1 Replies

6. Shell Programming and Scripting

Retrieve values using soap moudle

Can someone tell me how to know the values used in soap api. I need to know what values are used in soap xml. Can we get all the values used in soap api. I know that we can get it by using SOAP::Lite module in perl. But it is like we are supplying keys and we are getting values. I want... (0 Replies)
Discussion started by: Anjan1
0 Replies

7. Shell Programming and Scripting

how to retrieve lines that the first 4 columns have different values

Hi, all: I am not familiar with unix,and just started awk scripts. I want to retrieve lines that have the first 4 columns with different values. For example, the input is like this (tab delimited file with one header) r1 A A A A x r2 A B B A x r3 B B B B x the output should be (header is... (15 Replies)
Discussion started by: new2awkin2011
15 Replies

8. UNIX for Dummies Questions & Answers

need to retrieve values of parameter

Hi, I am just new to this shell scripting wizard..i have a text file which contains content as below: Parameter=10; What should be the script which only fetches the value 10 not the Parameter. The idea is to get the logic behind getting the value alone not its parameter,.... (6 Replies)
Discussion started by: d8011
6 Replies

9. Shell Programming and Scripting

have to retrieve the distinct values (not duplicate) from 2nd column and display

I have a text file names test2 with 3 columns as below . We have to retrieve the distinct values (not duplicate) from 2nd column and display. I have used the below command but giving some error. NS3303 NS CRAFT LTD NS3303 NS CHIRON VACCINES LTD NS3303 NS ALLIED MEDICARE LTD NS3303 NS... (16 Replies)
Discussion started by: shirdi
16 Replies

10. Shell Programming and Scripting

to retrieve unique values

Hi all, I have a 10.txt file. In this file 2 words are present by name Active and Inactive and these words are repeated 7000 times. I want to take the unique 2 words from this 7000 lines. Thanks Mahalakshmi.A (3 Replies)
Discussion started by: mahalakshmi
3 Replies
Login or Register to Ask a Question