How to access files from different directories and to perform search action in those files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to access files from different directories and to perform search action in those files?
# 1  
Old 10-13-2011
How to access files from different directories and to perform search action in those files?

Hi,
I want to access files from different directories (for example: /home/dir1/file1 , /home/dir2/file2 ...) Like this i have to access these files(file1, file2...).
# 2  
Old 10-13-2011
Code:
 
grep "what you want to search" < /home/dir1/file1

What is the problem ?

Used Code tags

Last edited by max_hammer; 10-13-2011 at 09:58 AM..
# 3  
Old 10-14-2011
How to access files from different directories and to perform search action in those files?

Thanks for your reply Max,
But actually i dont know wat are all the files will in that directory and i have to access those files sequencely and one more thing directory(dir1) also getting change. In short, i have access different files from different directories.
# 4  
Old 10-14-2011
Code:
find /home/ -type f | xargs grep "what you want to search"

This will do the job

find command will list all the files recursivily and xargs will make them as agrument to your grep command

Let me know if you still face any issue
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to perform an action similar to vlookup between two csv files in UNIX

Hi, I am new to awk/unix and am trying to put together an awk script to perform an action similar to vlookup between the two csv files. Here are the contents of the two files: File 1: Date,ParentID,Number,Area,Volume,Dimensions 2014-01-01,ABC,247,83430.33,857.84,8110.76... (9 Replies)
Discussion started by: Prit Siv
9 Replies

2. Red Hat

Access time of files and directories

My query please: What I saw how access times of a file and directories work. 1) For a file the access time is the time when I 1st access it after last modification of the file, i.e., if the file is modified at 10 AM and then I access it at 11 AM. After than whenever I access without... (7 Replies)
Discussion started by: ravisingh
7 Replies

3. Shell Programming and Scripting

Recursive search for files and copy to new directories

So I have extremely limited experience with shell scripting and I was hoping someone could point out a few commands I need to use in order to pull this off with a shell script like BASH or whatnot (this is on OS X). I need to search out for filenames with account numbers in the name itself... (3 Replies)
Discussion started by: flyawaymike
3 Replies

4. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

5. UNIX for Dummies Questions & Answers

Loop through Sub Directories and search for set of files

I have the below directory in unix environment /home/bkup/daily: ls -lrt drwxrwx--x 2 user user 256 Jan 12 18:21 20110112/ drwxrwx--x 2 user user 256 Jan 13 17:06 20110113/ drwxrwx--x 2 user user 256 Jan 14 16:44 20110114/ drwxrwx--x 2 user user ... (2 Replies)
Discussion started by: prasannarajesh
2 Replies

6. Shell Programming and Scripting

shell script - search a file and perform some action

hi, i have a service on unix platform, it will generate traces in a particular folder i want to check using shell script if traces exist, then perform some action else continue to be in loop. filename is service.tra can you please help? thanks (4 Replies)
Discussion started by: gauravah
4 Replies

7. Shell Programming and Scripting

Need help in searching 2 files for strings then perform an action

I have 2 files. I basically want to search both of them to see if the 1st column ($1) matches and if it matches then check to see if the 2nd column ($2) matches, then execute some code showing the results of the matches. File 1: AAA 123 misc blah BBB 456 CCC 789 File 2: ... (2 Replies)
Discussion started by: streetfighter2
2 Replies

8. Shell Programming and Scripting

Search directories for files with zero sizes to delete

Hi, I am trying to write a script that will use ls on a directory and list the files one at a time and their size. If the size is 0 i want it to ask me if I want to delete it (yes or no). If I say yes, I want it to delete but it won't know what the file name is just from running from the script.... (2 Replies)
Discussion started by: akeenabawa
2 Replies

9. Shell Programming and Scripting

Perform action file name written to the pipe

Hello, I have a script that monitors files uploaded via ftp. After a successful upload, the file name is written to the pipe. There is another program that reads this pipe and allows automatically run any program or script ( say test.sh ) to process the newly uploaded file. cat test.sh... (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies

10. UNIX for Dummies Questions & Answers

Search for files in multiple directories

I want to search for a file pattern in more than one directory. How I need to do that? Here is the scenario: I am having a directory structure like the following: /log ...../20051001 ..........ftp_server_20051001.log ..........ftp_down_server.log ..........ftp_up_server.log... (7 Replies)
Discussion started by: ravikirankethe
7 Replies
Login or Register to Ask a Question