How to use grep function for searching LIKE result
I am required to map file code, which is in another file, by using
filename. But, my generated txt filenames are in the following format:
student_name20060811.txt, school_address20060711.txt,
home_address20050901.txt... I tried to use grep function and then
append the file code in the txt file.
My problem is the grep function has to match student_name20060811.txt
and then get the ABC001 file code. It can't get student_name as key
only. Could you give me some advices on my code.
I got a file code reference table and its format is as follow;
student_name ABC001
school_address CDE002
home_address EFG003
....
My shell script code:
#bin/sh
....
filecode_connect = $filelocation/referencefilename.cfg
....
'bcp views/stored procedures data and output as .txt files
....
for f in *.txt
do
mv -i "$f" "$f.bak"
{
mappedcode = `grep $f $filecode_connect | cut -f2 -d" "`
printf "$mappedcode" "$(date +%y%m%d)"
cat "$f.bak"
printf "%s\n" $(( $(wc -l < "$f.bak") + 2 ))
} >"$f"
done
My desired output format for student_name file for example:
ABC001060811
bcp output data
^^^^^^504 (<- number of rows count, ^ is space)
Cheers
Bon
|