filtering with find command...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers filtering with find command...
# 1  
Old 03-16-2005
filtering with find command...

dear all,
i have a rather simple question that I cannot seem to find an answer to..
i have a directory with 8 base directories and 30 something subdirectories.. in each subdirectory I have aloccated base files (empty files) that I can refer to from find.. these base files will then have three or four files created with the same name with the suffix .doc-{1,2,3,4} ... the base file stays empty. when I run a find on the directory I find .doc files or empty files to create doc files from.. my question is when I need to find empty files that have no other files attached to them how would I filter out the empty files that have .doc files attatched to them using find.. ..
moxxx68
# 2  
Old 03-16-2005
to get empty doc files ....

Code:
find . -name *.doc -type f -size 0

Sorry , i have not understood your question fully.
# 3  
Old 03-16-2005
thats O.K...
thanx anyway
# 4  
Old 03-16-2005
moxxx68, I believe that I understand the question. But I don't think you can do that with find alone. find can't really select a file based on the presense or absense of similiarly named files co-residing in the same directory. You would need to write a script for this.
# 5  
Old 03-17-2005
here is a script that I worked on last night for about an hour without any luck..
the -name option won't accept the vars that I give it..
#!/bin/bash
#_filter



i=`find . -type f -name "*.doc*" -print | xargs sed -e 's/\.\/.*\///' -e 's/\.\///'`
file=${i//.doc-1/}
if [ $file -f ] then
find $1 -type f ! -name "$file" ! -name "$i" -print
fi

..... could use some help
thanx moxxx68
# 6  
Old 03-17-2005
If I understand completely, this should do it...
Code:
#! /usr/bin/ksh
find . -name \*.doc -print | while read docfile ; do
      dir=${docfile%/*}
      file=${docfile##*/}
      cd $dir
      ls ${file}-* >/dev/null 2>&1 || echo $file in $dir
      cd -
done
exit 0

opps..I had a typo...fixed now

Last edited by Perderabo; 03-17-2005 at 10:29 AM.. Reason: Fix typo
# 7  
Old 03-17-2005
MySQL

perderabo..
worked great.. I just have to adjust a few things to try and get the opposite too.
thanx moxxx68.....
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Filtering netstat command output

Hi All, I am trying to collect the listen ports info from netstat command in centos 7 From that info i am trying to collect all the foreign address IP for those ports. I am using below script to do the same. netstat -an |grep -w "LISTEN" |grep -v "127.0.0.1" |awk '{print $4}' >... (3 Replies)
Discussion started by: sravani25
3 Replies

2. Shell Programming and Scripting

Egrep -v command not filtering correctly

Hello guys, I have an issue when trying to do an egrep -v on a file, let me show you. I want to filter the last column as to where it filters out the columns with asterisks and zeros ( * and 0 ) it is working properly up to a certain point where I have a value of '10000' which is also getting... (3 Replies)
Discussion started by: evergreen
3 Replies

3. Shell Programming and Scripting

Filtering protocol and string in tcpdump command?

Hello to all in forum, Maybe some unix expert could help me. I have the following tcpdump command: tcpdump -i any port 13907 -s 0 -w Out.cap I would like to run tcpdump to only capture data related with especific string. Within the dump the protocol is GSM MAP and the string is Address... (0 Replies)
Discussion started by: cgkmal
0 Replies

4. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

5. Shell Programming and Scripting

filtering input from read command

I need help understanding a script I'm modifying which someone else has written. Basically I’m looping through a buffer that holds records fetched from a database query. I need a way to separate the primary key values from other attributes in the result. Heres the code: BUFF=buffer_file >... (5 Replies)
Discussion started by: d3mon_spawn
5 Replies

6. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

7. Shell Programming and Scripting

Command filtering ONLY rows NOT beginning with '*'

I need a command which filters rows ONLY NOT beginning with '*' So far I have following NOT sufficient command, because it does not include ALL possible literals except of '*' grep ^ INPUT_FILE >>OUTPUT_FILE Is it possible to write something like grep NOT ^ INPUT_FILE... (3 Replies)
Discussion started by: ABE2202
3 Replies

8. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

9. Shell Programming and Scripting

Little bit weired : Find files in UNIX w/o using find or where command

Yes , I have to find a file in unix without using any find or where commands.Any pointers for the same would be very helpful as i am beginner in shell scritping and need a solution for the same. Thanks in advance. Regards Jatin Jain (10 Replies)
Discussion started by: jatin.jain
10 Replies

10. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies
Login or Register to Ask a Question