10-09-2007
1,
0
Join Date: Oct 2007
Last Activity: 5 November 2007, 12:57 PM EST
Posts: 1
Thanks Given: 0
Thanked 0 Times in 0 Posts
Begining Shell scripter
I am trying to write for my class project a shell script, using bourne shell, that will take one command, either -l or -w. If -l is entered then the script should output the names of all the files in my working directory sorted in increasing order of the number of lines in the file. If -w is input then the same ill be done except that it will be sorted in increasing order by the number of words in the files. I know the solu'n will use the command ls and a pipeline to sort. but I don't know how to list the files or sort the files by the number of words or lines that they have. so far I have
#!/bin/sh
print=`ls | sort`
echo $print
this is not exactly correct but if I knew how to sort the files according to the number of lines each had, then I could rearrange this code to adapt.
Any help would be really appreciated. The project is not worth much at all but I am curious as how to sort this way. Thank you.