The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sorting your data with msort iBot UNIX and Linux RSS News 0 05-19-2008 11:20 AM
Sorting data and place them in different folders Vinaykumar1 UNIX for Dummies Questions & Answers 29 05-14-2008 08:47 AM
Sorting blocks of data alfredo123 Shell Programming and Scripting 8 07-05-2007 10:53 AM
Newbie Awk data sorting i_am_a_robot Shell Programming and Scripting 5 05-04-2007 07:33 AM
Perl: Sorting an associative array tine Shell Programming and Scripting 2 10-29-2003 04:11 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-04-2007
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
sorting data using array in ksh

plz help me..........i have a ksh script that sorts data in ascending order.
the 1st half is correct,but for the line no 31 its showing problem

1 #!/bin/ksh
2
3
4
5 echo "Enter the array length"
6 read num
7
8
9 echo "enter the elements"
10
11 i=0
12
13 while (( i < num ))
14 do
15 read element1[i]
16 i=`expr $i + 1`
17 done
18
19 i=0
20 echo "The elements are"
21 echo ${element1[*]}
22
23 i=0
24 temp=0
25 while (( i < num ))
26 do
27
28 j=`expr $i + 1`
29 while (( j < num ))
30 do
31 if (( element1[i] > element1[j] ))
32 then
33 temp=$element1[i]
34 element1[i]=$element1[j]
35 element1[j]=$temp
36 else
37 echo " "
38 fi
39 j=`expr $j + 1`
40 done
41 i=`expr $i + 1`
42 done
43
44 echo "The element in ascending order are "
45 echo ${element1[*]}
----------------------------------------------------------------------
  #2 (permalink)  
Old 12-04-2007
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
Hi,

The problem in the above code is in accessing the array elements.

The array elements should be accessed as ${array[num]}

Use the below code in your script,

if (( ${element1[i]} > ${element1[j]} ))
then
temp=${element1[i]}
element1[i]=${element1[j]}

Regards,
Chella
  #3 (permalink)  
Old 12-04-2007
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
thanks a lot dear.got it

very much thanks to u.
hey can u also tell me how to blink a text in a file and contnue with the rest of the program.
actually it only blinks and i cannot do the rest as i should wait for the blinking to stop

can u show me a simple example in ksh
  #4 (permalink)  
Old 12-04-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
Ordinarily, yes, you would need to quote subscripted variables within braces "{ }" to protect the square brackets "[ ]" from the shell when accessing them. (You don't need to do this when setting them.) This should not be necessary inside the evaluation of double-parenthesis "(( ))". So the problem is not at line 31, but at 33, 34, and 35, using the syntax as suggested above. It just shouldn't be needed in the "if" clause.

You can blink text with "tput" if your terminal type supports blinking text. See the man page of tput for the correct options to use (i.e., I can't remember!)
  #5 (permalink)  
Old 12-04-2007
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
thanks dear for ur suggestion !

i have tried that but not able to blink the text simultaneously and proceed with the prorgam
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0