Afficher un message
Vieux 18/08/2006, 01h05   #2
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to use grep function for searching LIKE result

In article <1155827289.320771.99230@m79g2000cwm.googlegroups. com>,
bonnie.tangyn@gmail.com wrote:

> 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:


You've got some basic problems understanding shell syntax.

>
> #bin/sh


That should be #!/bin/sh

> ...
> filecode_connect = $filelocation/referencefilename.cfg


You can't have spaces around the = in an assignment.

> ...
> '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" "`


# Remove the yyyymmdd.txt suffix from the filename
key=${f/????????.txt/}
mappedcode=`grep $key $filecode_connect | cut -f2 -d" "`

> printf "$mappedcode" "$(date +%y%m%d)"


printf "%s%s\n" $mappedcode `date +%y%m%d`

> cat "$f.bak"
> printf "%s\n" $(( $(wc -l < "$f.bak") + 2 ))


To get the desired spacing, change the printf format to "%9d\n".

> } >"$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


--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
 
Page generated in 0,05402 seconds with 9 queries