Filtering a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Filtering a file
# 1  
Old 06-01-2010
Filtering a file

I have a list of directories looking something like;

Code:
/usr/local/1/in
/usr/local/1/out
/usr/local/1/archive
/usr/local/2/in
/usr/local/2/out
/usr/local/2/archive
/usr/local/3/in
/usr/local/3/out
/usr/local/3/archive

Is there a way I can filter the out and archive directories so I can use them as a variable in a "find" script.

E.g. I want to run;

Code:
find ${archive} -type f -mtime +6 -exec rm {} \;

On only the archive directory and;

Code:
find ${out} -type f -mtime +2 -exec mv {} ../archive \;

Only on the out directory.
JayC89
# 2  
Old 06-01-2010
Something like this?
Code:
find /usr/local/*/archive -type f ...

# 3  
Old 06-01-2010
Quote:
Originally Posted by pludi
Something like this?
Code:
find /usr/local/*/archive -type f ...

Hi Pludi,

I was looking for it in a variable if possible. I am aware of out to do it statically like you mentioned however if the list was to ever change e.g.

Code:
/usr/local/1/in
/usr/local/1/out
/usr/local/1/archive
/usr/local/1/test/in
/usr/local/1/test/out
/usr/local/1/test/archive

The location of the out\archive directories would differ so a static /usr/local/*/out wouldnt suffice, would it?
JayC89
# 4  
Old 06-02-2010
Some versions of find (AFAIK GNU find and HP-UX find) support a -path predicate:
Code:
find /usr/local -path '*/archive/*' -type f ...

# 5  
Old 06-02-2010
Code:
find /usr/local -type d | grep -E 'out$|archive$'

# 6  
Old 06-02-2010
Thanks for all the replies guys. At the moment I have ended up using;

Code:
#
# Run the archive clear down
#
for archive in `cat ${client_list} | grep /archive` ; do find ${archive} -type f -mtime +6 -exec rm -f {} \; ; done

#
# Run the out clear down
#
for out in `cat ${client_list} | grep /out` ; do find ${out} -type f -mtime +2 -exec mv {} ${out}/../archive \; ; done

Which works perfectly, however what I was really looking for is something similar to a case script where it checks whether it contains archive or out and runs the relevant command - just to make it a little tidier!
JayC89
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help of filtering string from a file.

HI All, We have an Redhat Machine, And some folder with couple simple text files, this files containing a lot of lines with various strings and IP address with different classes. The Requirement in eventually , is to pass the all various IP addresses to Excel. My question is : what is... (4 Replies)
Discussion started by: James Stone
4 Replies

2. Shell Programming and Scripting

Filtering first file columns based on second file column

Hi friends, I have one file like below. (.csv type) SNo,data1,data2 1,1,2 2,2,3 3,3,2 and another file like below. Exclude data1 where Exclude should be treated as column name in file2. I want the output shown below. SNo,data2 1,2 2,3 3,2 Where my data1 column got removed from... (2 Replies)
Discussion started by: ks_reddy
2 Replies

3. UNIX for Dummies Questions & Answers

Filtering records from 1 file based on some manipulation doen on second file

Hi, I am looking for an awk script which should help me to meet the following requirement: File1 has records in following format INF: FAILEd RECORD AB1234 INF: FAILEd RECORD PQ1145 INF: FAILEd RECORD AB3215 INF: FAILEd RECORD AB6114 ............................ (2 Replies)
Discussion started by: mintu41
2 Replies

4. Shell Programming and Scripting

filtering the log file

Hi i have a log file like example below. I need only one field from below log all other need to be truncated from the log file. 2011-06-13 15:10:53,498 INFO ext.SP->CAL (log point 5) can any body help on this please. Thanks (4 Replies)
Discussion started by: mostwantedkisss
4 Replies

5. Shell Programming and Scripting

filtering the rows in a file

hi all, please help on this isssue, i have a file which contains something like this and i want to seprate the servers which has vasd.pid ,i need only server names. i want output something like this which vasd.pid . server1 server3 server4 (4 Replies)
Discussion started by: sudharson
4 Replies

6. Shell Programming and Scripting

Questions on File filtering

I have a file test.txt with the lines below : $ cat test.txt AAA 1 AAA 2 BBB 5 BBB 7 BBB 9 CCC 3 CCC 4 DDD 6 EEE 5 I want to filter the file above to make it have unique rows with the condition that if there are rows with the same value in the first column I want the row with the... (5 Replies)
Discussion started by: stevefox
5 Replies

7. UNIX for Dummies Questions & Answers

Filtering Log file

Hi, Iam trying to filter a log file in the below format |fffff|hhhhh|ffff|dd|mm|yy|hh|min||dd|mm|yy|hh|min the first set of |dd|mm|yy|hh|min is when the application ran the second set of |dd|mm|yy|hh|min when it ended. I will be removing the last of the months in the log file to... (1 Reply)
Discussion started by: baanprog
1 Replies

8. Shell Programming and Scripting

Filtering line out of file

Hy, I would like to extract lines within following file, 4TX + 4XFUT + 4XBACK + 4Xexp: theo. actual start of day: -2 5 end of day: 5 4 profit: 2 -1 ==================== trade profit: 9 -2... (9 Replies)
Discussion started by: sam786
9 Replies

9. Shell Programming and Scripting

Urgent: Filtering a File

Hi all I need to write a small shell script, where we have one Log file and another File 1 containing some tags in it. My log file can have multiple tags in it which can be other than the ones that are part of File 1. So I need to write a script that will run and test whether the tags... (5 Replies)
Discussion started by: HItesh
5 Replies

10. UNIX for Dummies Questions & Answers

filtering by file size

Hi ! I wanted to know how can i filter files by "size range". like : getting all the files that are bigger than 100 byte and smaller than 200 byte ? I want to make it as a script... I noticed the unix command : find . -size +100c but i also want limit it's upper bounds. so something... (2 Replies)
Discussion started by: nir
2 Replies
Login or Register to Ask a Question

Featured Tech Videos