Right. Basically what I want to achieve is a bash script which takes the name of a file as the first argument and displays lines from the input file that are:
- Not directories
- Executable And these lines should be sorted in an ascending file size order.
The input file example that I'm using has the following content:
-rw-r--r-- 1 root software 36 Dec 3 14:27 config
-rwxr-xr-x 1 root software 72 Dec 3 14:27 config2
-rw-rw-r-- 1 jonathan software 7410294 Dec 3 14:28 even larger file
-rwxrwxr-x 1 jonathan software 17290686 Dec 3 14:29 even larger file2
-rwxrwxr-x 1 jonathan software 2470098 Dec 3 14:28 large file
-rwxr-xr-x 1 andrew software 823366 Feb 11 16:25 myprogram
-rwxrwxr-x 1 jonathan software 29568 Dec 3 14:25 script
drwxrwsr-x 2 andrew software 4096 Dec 3 19:24 testdir1
drwxrwsr-x 2 bob software 4096 Dec 3 10:21 testdir2
drwxrwsr-x 2 david software 4096 Aug 23 14:24 testdir3
drwxrwsr-x 2 david software 4096 Dec 3 13:32 testdir4
drwxrwsr-x 2 james software 4096 Jan 5 14:24 testdir5
-rw-rw-r-- 1 james software 85 Dec 3 14:24 testfile1
I have written the script to ask for the file name and print the content of the file:
#!/bin/bash
echo "Please enter your filename:"
read filename
while read line;
do echo -e "$line\n";
done < $filename
But I don't know what's the command to look for the content line by line and search for lines which don't contain "drw" and also how to sort the lines by the size given in the example input file.
EDIT: This is the 2nd part of my problem. Now I want to modify the script to take a second argument, which if supplied is assumed to be the user name. Only lines matching the user name will be printed.
Eg: "jonathan" would print the following:
-rwxrwxr-x 1 jonathan software 29568 Dec 3 14:25 script
-rwxrwxr-x 1 jonathan software 2470098 Dec 3 14:28 large file
-rwxrwxr-x 1 jonathan software 17290686 Dec 3 14:29 even larger file2