FIND w/ multiple expressions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FIND w/ multiple expressions
# 1  
Old 07-16-2012
FIND w/ multiple expressions

For reference i am still a newb at scripting, but i have what i think is a complex issue.

I need to run a FIND on / to identify all files and print them to >> $TEMPFILE
I need to avoid MVFS
I need to avoid /var/tmp/nastmp/

I was trying find / \( -type d -name nastmp -prune \) -a \( -fstype mvfs \) -print

But this is not working at all. I can get them to work separately but i need both conditions to be met.

Can someone point me in the right direction?

Last edited by nitrobass24; 07-16-2012 at 07:45 PM..
# 2  
Old 07-16-2012
Hi, nitrobass24:

You want to use a boolean OR instead of AND. Use two -o operators between the three expressions (keeping the -print last).

Regards and welcome to the forum,
Alister
# 3  
Old 07-16-2012
Ahh i see.

Ok so i have
Code:
find / \( -type d -name nastmp -prune \) -o \( -fstype mvfs \) -o -print

But I am getting directories printed to the file instead of files only. Is there a way for me to specify that only files get written to log?

Last edited by Franklin52; 07-24-2012 at 08:34 AM.. Reason: Please use code tags for data and code samples, thank you
# 4  
Old 07-16-2012
Quote:
Originally Posted by nitrobass24
Ahh i see.

Ok so i have

find / \( -type d -name nastmp -prune \) -o \( -fstype mvfs \) -o -print

But I am getting directories printed to the file instead of files only. Is there a way for me to specify that only files get written to log?
Actually, that will descend into an mvfs filesystem (for some reason, I thought there was another -prune in the mvfs expression). What you want is something like the following (untested):
Code:
find / -type d \( -name nastmp -o -fstype mvfs \) -prune -o -type f -print

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 5  
Old 07-23-2012
Thanks to Allister, this is working great!

Just wanted to post my final code, hopefully it will help someone else in the future.

Code:
if [[ $OS = "HP-UX" ]]
then
$FIND / -type d \( -name nastmp -o -name centrify* \) -prune -o -type f -print >> $TEMPFILE
else
$FIND / -type d \( -name nastmp -o -name centrify* -o -fstype mvfs \) -prune -o -type f -print >> $TEMPFILE

This User Gave Thanks to nitrobass24 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed find multiple expressions plus next next line

Hello I am trying to write sed code where it will look through the text for lines with specific expression "Started by user" and when found, will also add the following line, and also lines with another expression "Finished:" sed -n '/Started by user/, +1p, /Finished:/'... (4 Replies)
Discussion started by: dlesny
4 Replies

2. Shell Programming and Scripting

BASH - Regular Expressions :Looking for one word on multiple lines.

Im looking for a bash solution that will use Regular Expressions (not perl, sed or awk) to check the example data below and then give me a status. which would be just simply Match or Mismatch. SYS PS1 is present. Fan status: Normal Input Voltage status: Normal ... (5 Replies)
Discussion started by: popeye
5 Replies

3. Shell Programming and Scripting

Replacing Multiple spaces with a single space but excluding few regular expressions

Hi All. Attached are two files. I ran a query and have the output as in the file with name "FILEWITHFOURRECORDS.txt " I didn't want all the spaces between the columns so I squeezed the spaces with the "tr" command and also added a carriage return at the end of every line. But in two... (3 Replies)
Discussion started by: sparks
3 Replies

4. UNIX for Advanced & Expert Users

Using find and regular expressions

Hi Could you please advise how can one extract from the output of find . -name "*.c" -print only filenames in the current direcotry and not in its subdirectories? I tried using (on Linux x86_64) find . -name "*.c" -prune but it is not giving correct output. Whereas I am getting... (9 Replies)
Discussion started by: tinku981
9 Replies

5. Shell Programming and Scripting

Find 2 expressions then print in a single line

Guys, need help. I have a file that contains something like this: abc def ghi jkl I want to print the first and last line of the file and the output should be in a single line. so, output should be like this: abc jkl (3 Replies)
Discussion started by: solidhelix08
3 Replies

6. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

7. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

8. UNIX for Dummies Questions & Answers

Regular Expressions -- Find spaces outside

Hello, I need help with using grep and regular expressions.... I have a long list of about 1000 lines of Chinese flashcards. Here's a small excerpt: 意文 yìwén (given name) 貴姓 guìxìng (honorable surname) 貴 guì (honorable) 姓 xìng (one's surname is; to be surnamed; surname) 呢 ne (interrogative... (2 Replies)
Discussion started by: arduino411
2 Replies

9. Shell Programming and Scripting

Output section of file between two expressions multiple times

Attached is the exact ouput of a vmware VDR log file I am working with but what I am trying to achieve is as follows: I need to output sections of the file using the string "Normal backup" as the start and "Duration" as the end to seperate files so I can then manipulate them further to create... (2 Replies)
Discussion started by: jelloir
2 Replies

10. Shell Programming and Scripting

Searching multiple files with multiple expressions

I am using a DEC ALPHA running Digital UNIX (formly DEC OSF/1) and ksh. I have a directory with hundreds of files that only share the extension .rpt. I would like to search that directory based on serial number and operation number and only files that meet both requirements to be printed out. I... (6 Replies)
Discussion started by: Anahka
6 Replies
Login or Register to Ask a Question