need help with shell script filtering files and sort! newbie question?

Hi folks,

I would like to get familiar with shell script programing.

The first task is:

write a shell script that:

scans your home-folder + sub-directory for all txt-files that all users of your group are allowed to read and write

then output these files sorted by date of last modification

the full path and the file's rights of each file shall also be shown!

so when I execute the script it shall give me an output like this:

"filename", "date of last modification", "rights of file", "full path"

I already tried something with "AWK" and several pipes between awk and the regular shell but I got a little bit mixed up so
I would be very pleased for any kind of help!

please post your awk solution. It looks like a home work :frowning:

that's how it looks like "now":

I made a lot of changes and so there's now a syntax error ,too.

after this awk I tried to get a list of directories to a file (temporary.any)
afterwards I wanted to read this file to do a cd "current directory from list" and an ls -l
to get it filter
but now I am lost ...
there must be a more simple way to solve it?

#! /bin/bash

find ~/ -type f -name "*.txt" -perm -'u=,g=rw,o=' -ls |
awk '/{
n = split ($11, dateinamen,"/");

 dateiname = dateinamen[n];
 print "FILENAME :"dateiname,"PATH :"$11,"FILERIGHTS :"$3,
 "LAST CHANGE :", $9, $8 \}' >> temporary.any

---------- Post updated 04-10-11 at 08:50 AM ---------- Previous update was 04-09-11 at 12:55 PM ----------

So I found a solution:

#! /bin/bash

find ~ -name "*.txt" -printf "%M %f %TY%Tm%Td%TH%TM%TS %TY %Tm %Td %TH %TM %p\n" | sort -nk3 |
awk '/^....rw/{

filecnt = filecnt + 1
printf ("No. %s", filecnt);
printf (" *** filename: %s", $2 )
printf (" *** filerights: %s", $1);
printf (" *** last change on: %s.%s.%s um %s:%s h\n",$6, $5, $4, $7, $8)
printf (" *** file path: %s\n", $9);

printf ("\n");
}'

So I found a solution:

#! /bin/bash

find ~ -name "*.txt" -printf "%M %f %TY%Tm%Td%TH%TM%TS %TY %Tm %Td %TH %TM %p\n" | sort -nk3 |
awk '/^....rw/{

filecnt = filecnt + 1
printf ("No. %s", filecnt);
printf (" *** filename: %s", $2 )
printf (" *** filerights: %s", $1);
printf (" *** last change on: %s.%s.%s um %s:%s h\n",$6, $5, $4, $7, $8)
printf (" *** file path: %s\n", $9);

printf ("\n");
}'
[/quote]

I just wondered how to change this not looking for file endings!

in Linux files aren't identified by file extension so now want to check the files mimetype using the "file" command

but I cant find a solution that can be adopted to my first solutin where I was looking for the file extension? any ideas?

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.