Register
It is currently Wed Jul 30, 2014 5:06 am

Get files or dirs, except ones on "exclude list"


All times are UTC - 6 hours


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPosted: Fri Dec 26, 2008 5:30 pm   

Joined: Fri Dec 26, 2008 4:30 pm
Posts: 4
I have a list with excluded files. How to get all except ones on "excluded list"?


Top
 Profile  
 PostPosted: Sun Dec 28, 2008 3:25 am   

Joined: Tue Dec 05, 2006 8:37 pm
Posts: 30
Location: Thiruvananthapuram / India
Hi,

The script found in http://bashscripts.org/viewtopic.php?p=2298 may help you :-)

Regards,
Lijeesh


Top
 Profile WWW YIM  
 PostPosted: Sun Dec 28, 2008 8:44 am   

Joined: Fri Dec 26, 2008 4:30 pm
Posts: 4
I saw that, but not understood. I'm beginner with no teacher. :(

Can you instruct me?

thanks


Top
 Profile  
 PostPosted: Mon Dec 29, 2008 4:12 am   

Joined: Tue Dec 05, 2006 8:37 pm
Posts: 30
Location: Thiruvananthapuram / India
Hi,

This script is used for searching and listing files and folders. It reads two input files include.txt and exclude.txt. include.txt contains the directories to be searched and exclude.txt contains the subdirectories (of those in include.txt) to be excluded from the search. The search result will be saved in result.txt.

By default, the script file, include.txt, exclude.txt and result.txt should be placed in the same directory. But if you want to change the location of txt files, edit the following lines in the script:

include='include.txt'
exclude='exclude.txt'
result='result.txt'

Any other help needed?

Regards,
Lijeesh


Top
 Profile WWW YIM  
 PostPosted: Mon Dec 29, 2008 2:12 pm   

Joined: Fri Dec 26, 2008 4:30 pm
Posts: 4
Hi,

Ow, I can understand it, I can't the code.
However this script isn't the better solution for me, I have only one list: the excluded list. If you want, may you write a new one or explain that to I try alone?

thanks in advance


Top
 Profile  
 PostPosted: Mon Dec 29, 2008 6:47 pm   

Joined: Tue Dec 05, 2006 8:37 pm
Posts: 30
Location: Thiruvananthapuram / India
Can you explain your requirement better? Do you want to search through a single directory or multiple directories and exclude subdirectories or specific file names specified in the exclude list?

Thnx,
Lijeesh


Top
 Profile WWW YIM  
 PostPosted: Mon Dec 29, 2008 9:03 pm   

Joined: Fri Dec 26, 2008 4:30 pm
Posts: 4
Specific directories and file names are on list. I want cat all subdirectories and files from a specified directory, except listed. In my head...
Code:
find /directory | "subtract" exclude.txt
:lol: :lol:

thanks

ps. sorry by my brazilian english :D


Top
 Profile  
 PostPosted: Tue Jan 06, 2009 11:30 am   

Joined: Tue Dec 05, 2006 8:37 pm
Posts: 30
Location: Thiruvananthapuram / India
Hi,

Here is the script:

Code:

#!/bin/bash

if [ $# -ne 2 ]
then
  echo "Usage: $0 search_path exclude_file"
  exit
fi

if [ ! -e $1 ]
then
  echo "Invalid search path"
  exit
fi

if [ ! -f $2 ]
then
  echo "Invalid exclude file"
  exit
fi

for path in $(cat $2)
do
  [ -e $path ] && excludepath=$excludepath"-path $path -prune "
done

excludepath=${excludepath//-prune -path/-prune -o -path}

[ -n "$excludepath" ] && excludepath=$(echo \( $excludepath \) -o | tr -s " ")

find $1 $excludepath -print



This script accepts two arguments, first is the search path and second is the exclude file.

Regards,
Lijeesh


Top
 Profile WWW YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP