While read -a line not working in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While read -a line not working in ksh
# 1  
Old 07-19-2017
While read -a line not working in ksh

Code:
while read -a line;

this is not working in ksh. what is the equivalent of this in ksh.


read: -a: unknown option

Last edited by rbatte1; 07-20-2017 at 07:29 AM.. Reason: Code tags
# 2  
Old 07-20-2017
You could try:

Code:
read words
set -A my_array $(printf "%s " $words)


eg:

Code:
$ read words
zero one two three

$ set -A my_array $(printf "%s " $words)
$ echo ${my_array[0]} ${my_array[3]}
zero three

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 07-20-2017
My version of ksh:
Code:
Version AJM 93u+ 2012-08-01

From the man page:
Code:
       read  [  -ACSprsv  ] [ -d delim] [ -n n] [ [ -N n] [ [ -t timeout] [ -u
       unit] [ vname?prompt ] [ vname ... ]
              ...
              nal device.  The -A option causes the variable vname to be unset
              and each field that is read to be stored in successive  elements
              of  the  indexed array vname.  ...

So instead of
Code:
read -a arr

use
Code:
read -A arr

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: Read line parse characters into variable and remove the line if the date is older than 50 days

I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Discussion started by: humble_learner
11 Replies

2. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

3. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

4. Shell Programming and Scripting

Working with FOR in ksh 88

Hi, I tried the following but giving me all the files in the directory , Where i need the files which are assigned to variable like below #!/bin/ksh Src_Dir="/home/etc" file_nm ="ab.temp" for File in `ls $Src_Dir/$file_nm*` do File=`basename $File` echo $File ... (2 Replies)
Discussion started by: smile689
2 Replies

5. Shell Programming and Scripting

[Solved] While read line and if statement not working

I'm looking for some help in figuring why my little bit of code will not process any entries other then the first one in my list. while read line ;do hostname=${line//\"} a=`ssh user@$hostname uptime;echo $?` if ];then dt=`date` touch... (6 Replies)
Discussion started by: whegra
6 Replies

6. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

7. Shell Programming and Scripting

While loop read line not working

Hi, I am trying to read a file line by line inside of a while loop. This while loop is part of a here document. while read line do ssh -t $2@$remotehost <<REMOTE ls path/to/dir > $path_to_dir while read line1 do echo "LINE --- $line" done... (4 Replies)
Discussion started by: mnanavati
4 Replies

8. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

9. Shell Programming and Scripting

read a file line by line in ksh

Hi, In ksh we use 'while read line' statement to read a file line by line. In my input file I have 5 spaces appended at the end of each line. When I use while read line statement it chops off the spaces at the end of each line Inp.txt aaaa<five spaces> bbbb<five spaces> cccc<five spaces> ... (3 Replies)
Discussion started by: chella
3 Replies

10. Shell Programming and Scripting

is there any way to read a line twice in KSH

Hi All, Is there any way to read the previous line in file reading ? or is there any way to read a line twice in KSH ? thanks in advance !! Srini (6 Replies)
Discussion started by: Srini75
6 Replies
Login or Register to Ask a Question