The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
searching a file straight_edge Shell Programming and Scripting 4 01-12-2007 05:21 AM
searching a file from folder debasis.mishra Shell Programming and Scripting 3 04-03-2006 03:25 AM
help searching log file with dates csaunders Shell Programming and Scripting 3 08-23-2005 08:50 AM
Append a field to the end of each line of a file based on searching another file. ultimate Shell Programming and Scripting 2 03-29-2005 07:21 AM
Help with searching a text file thekid2 Shell Programming and Scripting 6 01-01-2004 10:09 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-02-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
file searching...

Hi! i'm trying to do a script (i'm not an expert, as you will see...) to search files in a directory (and its subdirectories). I'd like to have something like this:

mysearch -a arg1 -b arg2 -c arg3 ecc...

I'd like to be able to search for files in different ways: for example, with

my search -n text* -u Eddie

i'd like to have all the files that begin with "text" owned by Eddie.
The options should be:
-n arg1 : search by name
-f arg2 : search by file dimension
-s arg3 : search by string
-d arg4 : search by date
-u arg5 : search by owner
etc.

I wrote these few lines (i'm not sure it's ok ) to manage the options:

#!/bin/bash
if [ $# = 0 ] ; then echo "Message A" ; fi ;
while getopts n:f:s:d:u: c
do
case $c in
n ) search_by_name ;;
f ) search_by_dim ;;
........
* ) echo "Message B"
esac
done

search_by_name, search_by_dim etc. must be replaced with instructions that find files with a certain name etc.

My problem is how to combine the different options? That way i can search files by name or by string but i don't know how to search by name AND by string... I don't know if it's clear...
I know it's a stupid question but as i said i'm not an expert
Any help would be really appreciated!
Thanks!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-02-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 218
have a look at the man page for find.

e.g
Code:
find . -name "text*" -user eddie
etc.

then if you still want your own script, you should be able to build up the relevant find command from input.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0