combine multiple finds into 1-liner


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting combine multiple finds into 1-liner
# 1  
Old 12-18-2010
combine multiple finds into 1-liner

How to combine 3 find statements into 1-liner?

find statements:

Code:
cd ${dir1} ; find . ! -name . -prune -type f | xargs file | grep -i ascii | cut -f1 -d: | xargs grep -l "${searchtxt}"
cd ${dir2} ; find . ! -name . -prune -type f | xargs file | grep -i ascii | cut -f1 -d: | xargs grep -l "${searchtxt}"
cd ${dir3} ; find . ! -name . -prune -type f | xargs file | grep -i ascii | cut -f1 -d: | xargs grep -l "${searchtxt}"

pls advise and thanks in advance.
# 2  
Old 12-18-2010
Code:
find "$dir1" "$dir2" "$dir3"  ! -name . -prune -type f | xargs file | grep -i ascii | cut -f1 -d: | xargs grep -l "${searchtxt}"

Should work.
No need to quote if you're sur there are no blanks in dir names.
# 3  
Old 12-18-2010
doesn't work Smilie
# 4  
Old 12-18-2010
Quote:
Originally Posted by ux4me
doesn't work Smilie
Do you have any idea how unhelpful that kind of response is?

What doesn't work?

The command, such as it is, works fine for me.
# 5  
Old 12-18-2010
the proposed find statement below doesn't work as expected:

Code:
find "$dir1" "$dir2" "$dir3"  ! -name . -prune -type f | xargs file | grep -i ascii | cut -f1 -d: | xargs grep -l "${searchtxt}"

no output from the above statement. this is because when dirs are specificied in the find, the statement couldn't find name "." which is not pruned.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine these two into one liner awk?

ignore the simplicity of the foo file, my actual file is much more hardcore but this should give you the jist of it. need to combine the two awks into one liner. essentially, need to return the value of one particular field in a file that has multiple comma separated fields. thanks guys cat foo... (1 Reply)
Discussion started by: jack.bauer
1 Replies

2. Shell Programming and Scripting

How can I do one liner import multiple custom .pm files in my perl script?

I am new for Perl I want to ask one question. I have around 50 custom packages which i am using in my Perl script. I want to import all .pm packages in my Perl script in an easy way. Right now i have to import each package individually. So Is there any way to do so?? Right Now i am doing like: ... (1 Reply)
Discussion started by: Navrattan Bansa
1 Replies

3. UNIX for Dummies Questions & Answers

renaming multiple files using sed or awk one liner

hi, I have a directory "test" under which there are 3 files a.txt,b.txt and c.txt. I need to rename those files to a.pl,b.pl and c.pl respectively. is it possible to achieve this in a sed or awk one liner? i have searched but many of them are scripts. I need to do this in a one liner. I... (2 Replies)
Discussion started by: pandeesh
2 Replies

4. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

5. Shell Programming and Scripting

awk: Multiple search patterns & print in an one liner

I would like to print result of multiple search pattern invoked from an one liner. The code looks like this but won't work gawk -F '{{if ($0 ~ /pattern1/) pat1=$1 && if ($0 ~ /pattern2/) pat2=$2} ; print pat1, pat2}' Can anybody help getting the right code? (10 Replies)
Discussion started by: sdf
10 Replies

6. Shell Programming and Scripting

awk multiple-line search and replace one-liner

Hi I am trying to search and replace a multi line pattern in a php file using awk. The pattern starts with <div id="navbar"> and ends with </div> and spans over an unknown number of lines. I need the command to be a one liner. I use the "record separator" like this : awk -v... (8 Replies)
Discussion started by: louisJ
8 Replies

7. UNIX for Dummies Questions & Answers

For Loop To Rename Multiple Files Finds One Non-existant File

Okay so here's something that's confusing me: I have a script that's designed to remove the words "new_" from the front of any file except two exceptions and it looks something like this... for i in new_* do if ] && ]; then j=`echo "$i"|cut -c5-` mv $i $j fi done ... (5 Replies)
Discussion started by: Korn0474
5 Replies

8. Shell Programming and Scripting

combine 2 awks statement into 1 liner

Using these 2 comands to concatenate both outputs into single file: cat testdata | awk 'BEGIN { FS="\n"; RS=""; } /<pattern1>/ {print}' > testdata1 cat testdata| awk '/<pattern2>/,EOF' >> testdata1 is it possible to combine both "awk" into 1-liner? pls advise and thanks in advance. (5 Replies)
Discussion started by: ux4me
5 Replies

9. UNIX for Dummies Questions & Answers

Squeezing multiple commands in one liner

i have two commands ls -l > aaaa tr < aaaa It give the out put :- TOTAL 16 -RW-R--R-- 1 SUBHO NONE 0 JUL 22 2009 AAAA DRWXR-XR-X 2 SUBHO NONE 0 JUL 22 20:55 DD -RW-R--R-- 1 SUBHO NONE 0 JUL 22 20:55 DDD -RW-R--R-- 1 SUBHO NONE 28 JUL 22 18:01 FF -RW-R--R-- 1 SUBHO NONE 93 JUL 22... (6 Replies)
Discussion started by: subhotech
6 Replies

10. Shell Programming and Scripting

Combine multiple columns from multiple files

Hi there, I was wondering if someone can help me with this. I am trying the combine multiple columns from multiple files into one file. Example file 1: c0t0d0 c0t2d0 # hostname vgname c0t0d1 c0t2d1 # hostname vgname c0t0d2 c0t2d2 # hostname vgname c0t1d0 c0t3d0 # hostname vgname1... (5 Replies)
Discussion started by: martva
5 Replies
Login or Register to Ask a Question