Operating System - Linux
1830165 Members
5960 Online
109999 Solutions
New Discussion

File cp script - questions about grep statement

 
rmueller58
Valued Contributor

File cp script - questions about grep statement

All, with the script below I am trying to define a parameter for empno with a FOR statement... the file I am pulling this information out of is a simple unload file from an informix db,

### flat file ### -- App 2 Hire
appid empno hire date
123456789|14522|01/31/2006|
987654321|14503|01/20/2006|
000111123|14504|01/19/2006|


# I am looking at the file name within the file system in the first FOR statement to determine the appid, this portion works, however the second FOR statement pulls all values from the $2 field from the flat file,

I want to define it so if a file exists and the associate "appid" has an "empno" then I copy the file.. I believe I am missing something in the second for loop and need a few extra sets of eyes to give an idea of what the heck i'm missing.. Any thought appreciated..

Rex M

export p1=/upload_resumes/
export p2=/upload_resumes/backup/
export wst=/wst-docs/applicant/
export mps=/mps-docs/mps-docs/applicant/
export esu=/esu-docs/applicant/
export plv=/plv-docs/

export wste=/wst-docs/employee/
export mpse=/mps-docs/mps-docs/employee/
export esue=/esu-docs/employee/
export plve=/plv-docs/employee/


echo NEW
for fn in `ls /upload_resumes/`
do
for dist in `echo $fn |awk '{print substr($1,1,3)}'`
# DISTRICT SPECIFIC INFORMATION
do
export dist

case $dist in
wst)
export distpath="$wst"
export distpathe="$wste"
;;
mps)
export distpath="$mps"
export distpathe="$mpse"
;;
esu)
export distpath="$esu"
export distpathe="$esue"
;;
plv)
export distpath="$plv"
export distpathe="$plve"
;;
*)
;;
esac

for appid in `echo $fn |awk -F_ '{print $2}'`
do
echo FILENAME: $fn
export appid
echo $appid
export source="$p1$fn"
echo $source

for empno in `grep -e "$appid" /tmp/"$dist"apphire.txt|awk -F"|" '{print $2}' `
do
export empno
echo $empno
echo $appid
done
read
if [ -n "$empno" ]
then
export destination="$distpathe$empno/$fn"
echo export destination="$distpathe$empno/$fn"

if [ -d "$distpathe$empno" ]
then
cp -f $source $destination
else
mkdir $distpathe$empl_no
cp -f $source $destination
fi

else
echo EMPL_NO has no valued position
fi

#END OF APPID SPECIFIC INFORMATION
done

#END OF DISTRICT SPECIFIC FILE MANIPULATION
done


4 REPLIES 4
rmueller58
Valued Contributor

Re: File cp script - questions about grep statement

HERE is the output i get when run the script.

export destination=/mps-docs/mps-docs/employee/14511/mpsplus_11_1.pdf
FILENAME: mpsplus_11_2.pdf
11
/upload_resumes/mpsplus_11_2.pdf
14501
11
14511
11

export destination=/mps-docs/mps-docs/employee/14511/mpsplus_11_2.pdf
FILENAME: mpsplus_1_1.pdf
1
/upload_resumes/mpsplus_1_1.pdf
14522
1
14503
1
14504
1
14383
1
14501
1
14510
1
14502
1
14511
1

export destination=/mps-docs/mps-docs/employee/14511/mpsplus_1_1.pdf
FILENAME: mpsplus_507745863_2.pdf
507745863
/upload_resumes/mpsplus_507745863_2.pdf
14511
507745863

export destination=/mps-docs/mps-docs/employee/14511/mpsplus_507745863_2.pdf
FILENAME: mpsplus_5_1.pdf
5
/upload_resumes/mpsplus_5_1.pdf
14522
5
14503
5
14504
5
14383
5
14501
5
14510
5
14502
5
14511
5
^[[A
export destination=/mps-docs/mps-docs/employee/14511/mpsplus_5_1.pdf
FILENAME: mpsplus_7_1.doc
7
/upload_resumes/mpsplus_7_1.doc
14501
7
14502
7
14511
7

export destination=/mps-docs/mps-docs/employee/14511/mpsplus_7_1.doc
FILENAME: mpsplus_9_1.doc
9
/upload_resumes/mpsplus_9_1.doc
14504
9
14501
9
14510
9
14502
9
rmueller58
Valued Contributor

Re: File cp script - questions about grep statement

found my own answer I think..

grep -w
rmueller58
Valued Contributor

Re: File cp script - questions about grep statement

the -w elimination one problem but I think my nesting is screwed up still..
rmueller58
Valued Contributor

Re: File cp script - questions about grep statement

I will repost.. I am still attempting to figure out why the "empno" variable and destination variables are not clearing with each iteration of the script.