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


 
Thread Tools Search this Thread
Top Forums Programming need help with shell script filtering files and sort! newbie question?
# 1  
Old 04-09-2011
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!
# 2  
Old 04-09-2011
please post your awk solution. It looks like a home work Smilie
# 3  
Old 04-10-2011
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");
}'
# 4  
Old 04-16-2011
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?
# 5  
Old 04-16-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

2. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

3. Shell Programming and Scripting

Newbie Question: What is php shell scripting?

I know php is a Web Development language but what does it have to do with shell scripting. I might be wrong about php. Is there a CLI? How do I make one and how does it work? Please don't answer these if you have any books on this. Please give names of good beginner books for php shell scripting... (3 Replies)
Discussion started by: orszhak
3 Replies

4. Shell Programming and Scripting

Asynchronous shell scripts question - newbie

Hi All, I am fairly new to UNIX and very new to this forum too. This is my first post here. Here is my scenario - I have 3 scripts script1, script2 and script3. I want to start script1 and script2 asynchronously. Upon completion of both scripts script1 and script2, i want to fire the last... (4 Replies)
Discussion started by: taskeen21
4 Replies

5. UNIX for Dummies Questions & Answers

Shell script which will sort all the files in a directory with the timestamp they were created

Team, Pls help writing a shell script which will sort all the files in a directory with the timestamp they were created. (like ls -lrt) (6 Replies)
Discussion started by: asappidi
6 Replies

6. Shell Programming and Scripting

Newbie Question - Help with script

Hi I have about 5000 expired images that need removed from disk. Instead of doing it manually I am trying to use the following script: #vi remove_expired_images FilePath=/Scripts for i in `cat $FilePath/backupid.txt` do #echo $i >> $FilePath/Jim.txt... (2 Replies)
Discussion started by: jamba1
2 Replies

7. Shell Programming and Scripting

Newbie Question: Killing a process using a supplied name to a shell script

Hi, I am trying to automate the killing of named processes of which I found a good solution here on the forums but as I am pretty much a begginer to linux I am having an issue. The code I found is: kill $(ps -ef | nawk '/monitoreo start/ { print $2}'} but what I want to do is replace... (3 Replies)
Discussion started by: TylrRssl1
3 Replies

8. Shell Programming and Scripting

Shell script to sort and execute files sequentially

Hi, I want to sort my files under a directory and execute them sequentially. For ex: my diir contains files: a_5.sql, ab_2.sql,abc_3.sql, acbd_1 ,ab_4.sql, etc. I want to execute the files based on the last number after underscore sequentially(i.e.. _1,_2,etc) . Can anybody help me? (5 Replies)
Discussion started by: MuraliKrisna
5 Replies

9. Shell Programming and Scripting

Newbie question-do I pause and exec my shell scripts?

Hi there, I'm writing a script to restore 3 directories and 3 mysql db's every 24 hours. While writing the script, I came across the thought... Do I need to pause between executions? Example: msql restore1.sql rm -Rf path1/* cp -Rf path1/* /restore1 chmod 777 /folder1/cache1 ... (2 Replies)
Discussion started by: semiotics101
2 Replies

10. UNIX for Dummies Questions & Answers

shell scripting newbie question

Hi all! I'm a newbie to shell scripting. I want to create a script that will store a line from a text file in a variable so I can then use it to open firefox with that text in the address bar (the text file contains a list of addresses). I have tried the following: #!/bin/sh a='sed -n 2p... (2 Replies)
Discussion started by: jazzman
2 Replies
Login or Register to Ask a Question