self-learning! my korn shell problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting self-learning! my korn shell problem
# 1  
Old 10-19-2010
self-learning! my korn shell problem

i am a beginner i m learning shell by myself
i have problem writing a korn shell that takes an absolute pathname to directory and display all ordinary files in the directory ordered by their length.
i was thinking use grep ls sort and sed. maybe, i m wrong! can someone tell me?

Last edited by babuda0059; 10-19-2010 at 06:47 AM..
# 2  
Old 10-19-2010
This sounds like homework. We have a special forum for that.

However:
Code:
#!/bin/ksh
# parms $1 = absolute path to files
path="$1"
cd $path
ls |
while read fname
do
   if [ -f $fname  ] ; then # is this a regular file, not a dir or pipe, etc
      ls -l $fname 
   fi
done | sort -n -k 5

watch spaces arounnd brackets....
# 3  
Old 10-19-2010
Code:
( find $path -type f | xargs -n101 ls -l ) | sort -n -k 5

This 101 is dedicated to dude DGnitPickett Smilie

Last edited by Scott; 10-19-2010 at 10:33 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 Beginners Questions & Answers

Looking for guidance on learning the shell

Hello everyone! I am a mechanical engineering student from Brazil, and I'm trying to get into numerical simulation in fluid dynamics. A teacher recommended OpenFoam and from what I've been reading, it seems that I need to get familiar with ''the Shell'' at first, and this is why I'm here. I... (2 Replies)
Discussion started by: Heisenflower
2 Replies

2. Shell Programming and Scripting

korn shell display lenght problem!!! i got stuck on this

Using the KSH, write a shell script called display_by_length, which takes an absolute pathname to a directory and displays all ordinary files in the directory ordered by their length; for each file listed, display the name of the file and its length - nothing else. Extend this script to take an... (1 Reply)
Discussion started by: babuda0059
1 Replies

3. Shell Programming and Scripting

unix korn shell leap years problem

Write a function called dateToDays that takes three parameters -a month string such as Sep, a day number such as 18, and a year number such as 1962-and return s the number of days from January 1, 1900, to the date. Notes: I am asking you to account for leap years. my script is not... (0 Replies)
Discussion started by: babuda0059
0 Replies

4. Shell Programming and Scripting

AIX Korn shell sed -s problem

In a Korn shell script I have, cat ../header | sed -e 's/flag1/$cnumb/g' > header.txt The header is short {{Company flag1}} But the result in header.txt is {{Company $cnumb}} The value of $cnumb is 120. I am trying to get the value of $cnumb into the header. I have tried /'$cnumb'/g,... (10 Replies)
Discussion started by: jcarrott
10 Replies

5. Shell Programming and Scripting

korn shell automation problem!

I got the task writting Korn Shell script to automate the tuxedo login so that users neednot have to enter options manually. I have done that using expect tool from the Unix but my manger told me its not secure so you have to do that using Kornshell without using Expect. Here is the way to login to... (0 Replies)
Discussion started by: pareshan
0 Replies

6. Shell Programming and Scripting

Problem with Korn Shell

My Korn shell script below is giving me the following error: ./test.ksh: 0403-057 syntax error at line 7 : 'then' is not matched. Can anyone provide a quick solution as to why the error is occurring? Thanks. #!/usr/bin/ksh typeset -i RecCount typeset -i RecCount2 RecCount=`db2 -x "select... (23 Replies)
Discussion started by: sasaliasim
23 Replies

7. UNIX for Dummies Questions & Answers

problem extracting substring in korn shell

hi all, I have read similiar topics in this board, but i didn' t find the posting which is the same with the problem i face.. I try to extract string from the end. i try to do this: num=abcdefghij num2=${num:-5} echo $num2 #this should print the last 5 characters (fghij) but it doesn;t... (3 Replies)
Discussion started by: nashrul
3 Replies

8. Shell Programming and Scripting

learning how to use shell script

hello everyone, i am still trying to get this script to work, but with no luck. It is a little beyond my knowledge of scripting at the moment. The beginner book i have has an exercise listed that asks me to write a script tha allows for user input. For example " what is your name: " and then you... (3 Replies)
Discussion started by: bebop1111116
3 Replies

9. Shell Programming and Scripting

problem with set command in korn shell

I have to copy an array to a temp variable and back after doing some functions. I am trying to see if it is possible to do without while loops.My closest try was set -A temp ${THE_ARRAY} # restore array after some actions set -A THE_ARRAY ${temp} The problem with above is that, the new... (1 Reply)
Discussion started by: vijay1985
1 Replies

10. Shell Programming and Scripting

Learning Shell Scripting

I'm new to UNIX and I want to learn Shell Scripting. I want a web site that has Shell Scripting tutorials. Any suggesstions?.? (3 Replies)
Discussion started by: liveapple2000
3 Replies
Login or Register to Ask a Question