grep a list of values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep a list of values
# 1  
Old 12-05-2006
Java grep a list of values

Hi everybody! Smilie Smilie Smilie Smilie

it's great to be here since this is my first post.


touch /base/oracle/FRA/XMUT00/RMAN_FLAG
touch /base/oracle/FRA/XRLL00/RMAN_FLAG

find directory name containing RMAN_FLAG :

$ find /base/oracle/FRA -name RMAN_FLAG -print|xargs -n1 dirname |sort -u
/base/oracle/FRA/XMUT00
/base/oracle/FRA/XRLL00


find all file named *.arc :

$ find /base/oracle/FRA -name "*.arc" -print
/base/oracle/FRA/XARS00/XARS00arch6563.arc
/base/oracle/FRA/XARS00/XARS00arch6562.arc
/base/oracle/FRA/XARS00/XARS00arch6559.arc
/base/oracle/FRA/XARS00/XARS00arch6560.arc
/base/oracle/FRA/XARS00/XARS00arch6561.arc
/base/oracle/FRA/XBIO00/XBIO00arch286.arc
/base/oracle/FRA/XMUT00/XMUT00arch3624.arc
/base/oracle/FRA/XMUT00/XMUT00arch3616.arc
/base/oracle/FRA/XMUT00/XMUT00arch3613.arc
/base/oracle/FRA/XMUT00/XMUT00arch3621.arc
/base/oracle/FRA/XMUT00/XMUT00arch3626.arc
/base/oracle/FRA/XRLL00/XRLL00arch5199.arc
/base/oracle/FRA/XRLL00/XRLL00arch5200.arc
/base/oracle/FRA/XRLL00/XRLL00arch5201.arc
/base/oracle/FRA/XRLL00/XRLL00arch5202.arc



I want to remove all *.arc files execpt those found in directories where RMAN_FLAG is present

I tried :

EXCLU=$(find /base/oracle/FRA -name RMAN_FLAG -print|xargs -n1 dirname |sort -u)

for file in $(find /base/oracle/FRA -name "*.arc" -print|grep -v ${EXCLU})
do
rm $file
done

but grep does not work with multiple values (I know perl grep function accept a list of values but shell grep don't Smilie )

any hints? using sed and/or maybe awk?

I'm on HPUX standard grep/awk/sed (not gnu)

thanks
# 2  
Old 12-05-2006
This works for me:

Code:
#!/bin/ksh

for f in $( find /base/oracle/FRA -name *.arc -print )
do
  if [ ! -f "$( echo $f | sed 's/\/[^\/]*$/\/RMAN_FLAG/' )" ]; then
    rm -f $f
  fi
done

I've tested it with ksh, maybe some small modifications are needed for other shells.

Darwin
# 3  
Old 12-05-2006
thanks that's exactly what I needed
# 4  
Old 12-06-2006
Quote:
Originally Posted by jolan_louve
Hi everybody! Smilie Smilie Smilie Smilie

it's great to be here since this is my first post.


touch /base/oracle/FRA/XMUT00/RMAN_FLAG
touch /base/oracle/FRA/XRLL00/RMAN_FLAG

find directory name containing RMAN_FLAG :

$ find /base/oracle/FRA -name RMAN_FLAG -print|xargs -n1 dirname |sort -u
/base/oracle/FRA/XMUT00
/base/oracle/FRA/XRLL00


find all file named *.arc :

$ find /base/oracle/FRA -name "*.arc" -print
/base/oracle/FRA/XARS00/XARS00arch6563.arc
/base/oracle/FRA/XARS00/XARS00arch6562.arc
/base/oracle/FRA/XARS00/XARS00arch6559.arc
/base/oracle/FRA/XARS00/XARS00arch6560.arc
/base/oracle/FRA/XARS00/XARS00arch6561.arc
/base/oracle/FRA/XBIO00/XBIO00arch286.arc
/base/oracle/FRA/XMUT00/XMUT00arch3624.arc
/base/oracle/FRA/XMUT00/XMUT00arch3616.arc
/base/oracle/FRA/XMUT00/XMUT00arch3613.arc
/base/oracle/FRA/XMUT00/XMUT00arch3621.arc
/base/oracle/FRA/XMUT00/XMUT00arch3626.arc
/base/oracle/FRA/XRLL00/XRLL00arch5199.arc
/base/oracle/FRA/XRLL00/XRLL00arch5200.arc
/base/oracle/FRA/XRLL00/XRLL00arch5201.arc
/base/oracle/FRA/XRLL00/XRLL00arch5202.arc



I want to remove all *.arc files execpt those found in directories where RMAN_FLAG is present

I tried :

EXCLU=$(find /base/oracle/FRA -name RMAN_FLAG -print|xargs -n1 dirname |sort -u)

for file in $(find /base/oracle/FRA -name "*.arc" -print|grep -v ${EXCLU})
do
rm $file
done

but grep does not work with multiple values (I know perl grep function accept a list of values but shell grep don't Smilie )

any hints? using sed and/or maybe awk?

I'm on HPUX standard grep/awk/sed (not gnu)

thanks
find /base/oracle/FRA -name RMAN_FLAG -print|xargs -n1 dirname |sort -u > tmp
for file in $(find /base/oracle/FRA -name "*.arc" -print|grep -v -f tmp)
Do the above modification to make grep work
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Grep document according to values

Hi, I have the following data that is 3-col, tab separated and looks something like this: inscription 1 1 ionosphere 0 0 magnate 0 1 majesty 1 0 meritocracy 0 0 monarchy 0 0 monkey 1 0 notepaper 1 1 The first column of the data is an ID, the second column of the data is a prediction... (4 Replies)
Discussion started by: owwow14
4 Replies

2. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

3. UNIX for Dummies Questions & Answers

How to use grep with numerical values?

I'm new to Unix and I have been trying to fix this problem for the past week. How would I use grep to display only certain numbers for a list. For example, if I have this list: Joe senior 4/50 John junior 25/50 Mary junior 41/50 Martha sophomore 2/50 ...How do I get a file... (1 Reply)
Discussion started by: PTcharger
1 Replies

4. UNIX for Dummies Questions & Answers

Grep multiple values

This for i in /dev/disco/*;do lvdisplay $i|grep -i size;done Return me every size of lvm in vg "disco" I want to return me,the size and the name of lvm,how to do this? Thanks (7 Replies)
Discussion started by: Linusolaradm1
7 Replies

5. Shell Programming and Scripting

Grep values from different lines

Hello, I have a log file with many lines and I want to grep pcific values from spcific lines, I'm not sure if it is possible or not Sample 16-11-11 19:54:13:INFO:Connection to device ip 20.10.11.23 took 0 16-11-11 19:54:13:FINE:Sending request. 16-11-11 19:54:13:INFO:Received response from... (3 Replies)
Discussion started by: roby2411
3 Replies

6. Shell Programming and Scripting

grep distinct values

this is a little more complex than that. I have a text file and I need to find all the distinct words that appear in a line after the word TABLESPACE when I grep for just the word tablespace, I get: how do i parse this a little better so i have a smaller file to read? This is just an... (4 Replies)
Discussion started by: guessingo
4 Replies

7. Shell Programming and Scripting

grep two values together.

Hi... I have a file abc.txt , havin more then 10,000 lines, each field separated by '#'. I want to grep 9914699895 and 999 from abc.txt I am trying cat abc.txt | grep 9914699895 | grep 999 but i am also getting data like 9991111111 or 9991010101 I want to grep "999" exactly and... (1 Reply)
Discussion started by: tushar_tus
1 Replies

8. UNIX for Dummies Questions & Answers

grep using ASCII values

machine: HPUX file: a.dat contents: decimal 1 decimal 2 string 1 string 2 ASCII value of 'd': 100. to grep lines that have 'd', I use the following command grep d a.dat My requirement: I should grep for lines that contain 'd'. But I should use ASCII value of 'd' in the command... (1 Reply)
Discussion started by: sriksama
1 Replies
Login or Register to Ask a Question