Operations on search results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Operations on search results
# 1  
Old 01-13-2006
Operations on search results

Hi, I am a newbie at Unix scritping, and I have a question.

Looking at the search functionality on Unix. Here I have a structure
root---------dir1 ------- file1, file2, file3
|_____dir2 ______file1@, file4
|_____dir3_______file1@, file5

Under root directory, I have directory dir1, dir2 , and dir3. In dir1, I have file1, file2, and file3. Under dir2, I have a hard link of file1, and file4. Under dir3, I have a symbolic link of file 1, and file5.

My queries are:
" find all the files that under dir1, but not under dir2 and dir3"
" find all the files that under dir2, but not dir3"
"find all the files that in both dir1, dir2, and dir3"

Would unix scripting be able to do that?
# 2  
Old 01-13-2006
This may sound a bit of naive method, but thats the immediate solution i can think for.
The script below solves your case 1. You can similarly write script for case 2 and 3.

## find all files that are under dir1, but not under dir2 or dir3
for k in `ls dir1`
do
if [ -f dir2/$k -o -f dir3/$k ]
then
echo "$k present in dir2 or dir3, so ignore"
else
echo "list this one $k"
fi
done
# 3  
Old 01-13-2006
I tried the script. I got the following error:

for: Command not found
k: Undefined variable

Also another question is if I give the hard link or the symbolic link of file1 another name, file6 and file7, will the above scripting work?

The new structure is as follows:
root---------dir1 ------- file1, file2, file3
|_____dir2 ______file6@, file4
|_____dir3_______file7@, file5

Thank you.
# 4  
Old 01-13-2006
hmm, for doesnt work, what shell are you using.
basically in the above script the check

" if [ -f ...."

checks for the existence of a file with that name. To check if the file is of a particular type like a link, directory or character special command, see the man page for "test" and use the appropriate flags. for eg for a symbolic link, you can test it as "-h".

The above script works for k-shell and bash shell too.

if you are very very new to shell scripting I will suggest you to do some reading first.
# 5  
Old 01-13-2006
I use tcsh. I checked and "foreach" instead of "for", "( )" instead of "[ ]" works in tcsh. Anyways, I tried bash, and the script is running now. Thanks for the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. What is on Your Mind?

Search Results are Now Responsive (Live)

Hey, It took me nearly 10 hours of work, but the forum search results are now fully responsive using CSS Flex and jQuery. By search results, I mean forum searches (not man page searches). Searches we do every day like: "Todays Posts", "New Topics", it's done! I have tested it and it... (0 Replies)
Discussion started by: Neo
0 Replies

2. What is on Your Mind?

Search Results (Search, New, and Today's Topics) Animation Switch

Hey, I added an animation switch on the search results page; so by default the thread previews are off, but if you want to look at them, just click on the green button and the thread previews will turn on (and back off). See image and attached animation: ... (1 Reply)
Discussion started by: Neo
1 Replies

3. Shell Programming and Scripting

Gawk Narrowing Down Search Results

I am using GAWK to search for a specific pattern: gawk '{IGNORECASE=1;} /<a href=/&&/\$/,/<\/a/' index.html <a class=author href="http://washingtondc.craigslist.org/search/?areaID=10&amp;amp;catAbb=sss&amp;amp;query=ps vita" title="craigslist washington, DC | all fo r sale / wanted search &quot;ps... (1 Reply)
Discussion started by: metallica1973
1 Replies

4. Shell Programming and Scripting

Can ctag and cscope support recording search results and displaying the history results ?

Hello , When using vim, can ctag and cscope support recording search results and displaying the history results ? Once I jump to one tag, I can use :tnext to jump to next tag, but how can I display the preview search result? (0 Replies)
Discussion started by: 915086731
0 Replies

5. Shell Programming and Scripting

Can BASH handle mathematical operations and do a Search & Replace?

Hello, I have a bunch of xml file that needs to have edits made and I was wondering if a BASH script could handle it. I would like the script to look within my xml files and replace all integers greater than 5px with a value that is 25% smaller. For example, 100px = 75px. Since the integers... (12 Replies)
Discussion started by: jl487
12 Replies

6. Shell Programming and Scripting

AWK - no search results

Hi all, I'm new to awk and I'm experiencing syntax error that I don't know how to resolve. Hopefully some experts in this forum can help me out. I created an awk file that look like this: $ cat myawk.awk BEGIN { VAR1=PATTERN1 VAR2=PATTERN2 } /VAR1/ { flag=1 } /VAR2/ { flag=0 } {... (7 Replies)
Discussion started by: hk18
7 Replies
Login or Register to Ask a Question