Need help for file filteration script......

Hiii all...

Pls help me out wid below prblm :
i have 5 files A,B,C,D and E located at /home/anubha
I have a file F located at /home/anubha/ed
File F has some records which can be matched in A,B,C,D and E
and another set of files on the basis of these filteration should be created i.e. G,H,I,J and K to be stored at /home/anubha/priya
Plsss help me out....pls pls pls..pls pls pls...:wall::wall:

I created below script for the same but it is just creating the files at locations not having any data in it....can you ppl plz lemme kno whr am i making mistakE???:(:(:(:(:(:frowning:

##filter.sh
#!/bin/bash
. anusha.sh
#we will use shell script to create these filter files as well
for file in `ls -1 ${SRC_DIR}/*.EDW`
do
       filename=`basename $file`
#echo "FILE NAME -" $filename
grep -e ${IMSI_FILTER}  ${file} >> ${TEMP_LOAD_DIR}
done

##anusha.sh

#!/bin/bash
export SRC_DIR="/home/anubha"
export LND_DIR="/home/anubha/priya"
export TEMP_LOAD_DIR="/home/anubha/priya"
export IMSI_FILTER="/home/anubha/ed"

1) Please give an exemple :
What do contains A B and E ?
How should look like G H and K ?

2) If you use redirection like ... >> ${MY_FILE}
${MY_FILE} should be a file (not a directory!)

3) Just to take some good habits : don't use " file " as a name of a variable since it already is a name of a unix command.

A,B,E are having 10 columns one of which is msisdn...
filter files F is having a list of msisdn...on the basis of F;A,B,C,D and E will be picked up with relevant rows and should be written as G,H and K..

---------- Post updated at 04:17 AM ---------- Previous update was at 04:14 AM ----------

A,B,E are having 10 columns one of which is msisdn...
filter files F is having a list of msisdn...on the basis of F;A,B,C,D and E will be picked up with relevant rows and should be written as G,H and K..

also below are the examples of the files i am taking into consideration :
F

msisdn
--------------
09311424354
09128734473
09487736472

A/B/C/D/E

msisdn             | imsi | name | subscription | product | date | recharge type
09311424354 | 09488439820 | ekta | yes | VAS | 2012-12-07 | IVR
09128734473 | 83974738734 | priya | no | Non VAS | 2011-08-11 | SMS
09376536263 | 63473627632 | shubhra | yes | VAS | 2011-07-07 | WAP
09655423434 | 13312353343 | shubhi | no | non VAS | 2011-05-04 | SMS
09473874383 | 36267267372 | amita | yes | VAS | 2011-04-05 | IVR

G/H/I/J/K

msisdn             | imsi | name | subscription | product | date | recharge type
09311424354 | 09488439820 | ekta | yes | VAS | 2012-12-07 | IVR
09128734473 | 83974738734 | priya | no | Non VAS | 2011-08-11 | SMS:o
awk 'NR==FNR{a[$1];next}FNR==1{f=FILENAME "_new"}($1 in a){print $0 > f}' F A B C D E

Your results will be in the files
A_new
B_new
C_new
...

Of course you can specify abolute path.

awk 'NR==FNR{a[$1];next}FNR==1{f=FILENAME "_new"}($1 in a){print $0 > f}' /home/anubha/ed/F /home/anubha/A /home/anubha/B /home/anubha/C /home/anubha/D /home/anubha/E

The awk code can also easyly be adapted to handle better the naming and the location of the target file i just did a quick shot here.

I haven't tried it so it may require some fix but you can give a try to the following

cd /home/anubha
awk 'BEGIN{n=split("ABCDEGHIJK",b,"");d="/home/anubha/priya"}
NR==FNR{a[$1];next}
FNR==1{for(i=0;++i<=n/2;) if(b==FILENAME) {t=d "/" b[i+5];break}}($1 in a){print $0 > t}' ./ed/F A B C D E

i use some crap version of linux....which doesnt hv sed/awk plugin installed in it....i dunno bt code doesnt wrk wid sed/awk...cn u suggst wid grep or fgrep... :o

ksh
cd /home/anubha
for i in A B C D E
do
t=$(echo "$i" | tr 'ABCDE' 'GHIJK')
sed 's/./^&/' /home/anubha/ed/F | grep -f - $i >$t
done

Why not to process them all at once and gather the result in a single file ?

cd /home/anubha
cat A B C D E >all
fgrep ./ed/F all >result