For Programmers: Free Programming Magazines  


Home > Archive > AWK > September 2006 > construct the filename to process??









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author construct the filename to process??
Atropo

2006-09-22, 6:56 pm

Newbie. I posted this before but had not realize how to accomplish.

have this file. input.txt

8092261513 4473.19OUT COMP20060905R1
8092410453 1105.92OUT COMP20060905R1
8092411018 3955.57OUT COMP20060904R1
..
..

the third field has a date "20060905"
the files of that date are:

OUT-20060905-041813.1.out
OUT-20060905-041844.1.out
OUT-20060905-045941.1.out
OUT-20060905-050150.1.out
..
..
I have to format the first field to look for it on those files of that
date..

qnt=(substr($1,1,3)"-" substr($1,4,3)"-" substr($1,7,10)) {print t} .

Ed Morton kindly showme this
awk -v RS="." -v FS=""
' NR=FNR{tels[$t];next}
$t in tels { "wich variables from second files?" }
' file1.txt OUT-20060905-041813.1.out

but i guess this is when you had passed the second filename as
parameter
here file1.txt has the formated number and using specific second
filename.

If i have a part of string of filename... "20060905" how could I

1.construct a unique file to process, maybe using cat inside awk..
2.process all files that matches

after all this how could I reference the data of the second file that
matches de values of first file??
very very lost. but I'm RTFM

Ed Morton

2006-09-22, 9:56 pm

Atropo wrote:
> Newbie. I posted this before but had not realize how to accomplish.
>
> have this file. input.txt
>
> 8092261513 4473.19OUT COMP20060905R1
> 8092410453 1105.92OUT COMP20060905R1
> 8092411018 3955.57OUT COMP20060904R1
> .
> .
>
> the third field has a date "20060905"
> the files of that date are:
>
> OUT-20060905-041813.1.out
> OUT-20060905-041844.1.out
> OUT-20060905-045941.1.out
> OUT-20060905-050150.1.out
> .
> .
> I have to format the first field to look for it on those files of that
> date..
>
> qnt=(substr($1,1,3)"-" substr($1,4,3)"-" substr($1,7,10)) {print t} .
>
> Ed Morton kindly showme this
> awk -v RS="." -v FS=""
> ' NR=FNR{tels[$t];next}
> $t in tels { "wich variables from second files?" }
> ' file1.txt OUT-20060905-041813.1.out
>
> but i guess this is when you had passed the second filename as
> parameter
> here file1.txt has the formated number and using specific second
> filename.
>
> If i have a part of string of filename... "20060905" how could I
>
> 1.construct a unique file to process, maybe using cat inside awk..
> 2.process all files that matches
>
> after all this how could I reference the data of the second file that
> matches de values of first file??
> very very lost. but I'm RTFM
>


I think what you're saying is that you want to read input.txt and use
that to:

a) from $3 derive the file names for subsequent processing, and
b) from $1 derive the string to search for in those subsequent files.

Since you refer to "cat" it seems like you're using UNIX so the simplest
solution would involve a mixture of awk and shell and so would be
somewhat OT here and more appropriate for comp.unix.shell but I'll risk
the flames this time in case I've misunderstood what you want:

I also think your final "substr()" whoud be substr($1,7,3) instead of
substr($1,7,10).

If all of the above is correct, one approach would be:

awk '{
qnt = substr($1,1,3) "-" substr($1,4,3) "-" substr($1,7,3)
gsub(/[^[:digit:]]/,"",$3)
print qnt, $3
}' input.txt |
while read qnt date
do
awk -v qnt="$qnt" '$0 ~ qnt{print FILENAME, qnt, $0}' OUT-*"$date"*
done

The above assumes you want to output the FILENAME, pattern searched for
and matching record. Adjust to suit.

Regards,

Ed.
Atropo

2006-09-25, 7:56 am


Ed Morton ha escrito:

> Atropo wrote:
>
> I think what you're saying is that you want to read input.txt and use
> that to:
>
> a) from $3 derive the file names for subsequent processing, and
> b) from $1 derive the string to search for in those subsequent files.


Exactly.

>
> Since you refer to "cat" it seems like you're using UNIX so the simplest
> solution would involve a mixture of awk and shell and so would be
> somewhat OT here and more appropriate for comp.unix.shell but I'll risk
> the flames this time in case I've misunderstood what you want:
>
> I also think your final "substr()" whoud be substr($1,7,3) instead of
> substr($1,7,10).
>
> If all of the above is correct, one approach would be:
>
> awk '{
> qnt = substr($1,1,3) "-" substr($1,4,3) "-" substr($1,7,3)
> gsub(/[^[:digit:]]/,"",$3)
> print qnt, $3
> }' input.txt |
> while read qnt date
> do
> awk -v qnt="$qnt" '$0 ~ qnt{print FILENAME, qnt, $0}' OUT-*"$date"*
> done
>
> The above assumes you want to output the FILENAME, pattern searched for
> and matching record. Adjust to suit.
>
> Regards,
>
> Ed.


Thanks Ed. exactly what I want. but I guess my awk doesn't support
[:digit:]. don't know either what version is. well the one that
comes with aix 5.2
Anyway a lot of thanks.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com