Home > Archive > AWK > January 2008 > Obtaining filename after receiving file from pipe
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 |
Obtaining filename after receiving file from pipe
|
|
| Roland Rau 2008-01-18, 6:59 pm |
| Dear all,
I extract zip compressed data from an archive and pipe the output into
gawk for further processing. Is there a way to obtain the name of the
archive or of the compressed file?
If I am a bit unclear, I hope this small example illuminates my point:
unzip -p data1990.zip | gawk 'END { print FILENAME }'
results in
-
Although this was not surprising, I would prefer to either have data1990
(i.e. the name of the compressed file, probably difficult since there
could be many files in one archive) or the name of the archive data1990.zip?
Is there a possibility to achieve this?
Hopefully, this is the right forum to ask this question.
Thank you very much in advance,
Roland
P.S. If it is necessary, I am using at this machine WinXP with unzip
5.50 and GNU Awk 3.1.4.
| |
| Ed Morton 2008-01-18, 6:59 pm |
|
On 1/18/2008 2:23 PM, Roland Rau wrote:
> Dear all,
>
> I extract zip compressed data from an archive and pipe the output into
> gawk for further processing. Is there a way to obtain the name of the
> archive or of the compressed file?
>
> If I am a bit unclear, I hope this small example illuminates my point:
>
> unzip -p data1990.zip | gawk 'END { print FILENAME }'
>
> results in
> -
Right, because gawk is operating on an input stream, not on a file.
> Although this was not surprising, I would prefer to either have data1990
> (i.e. the name of the compressed file, probably difficult since there
> could be many files in one archive) or the name of the archive data1990.zip?
> Is there a possibility to achieve this?
>
> Hopefully, this is the right forum to ask this question.
>
> Thank you very much in advance,
> Roland
>
> P.S. If it is necessary, I am using at this machine WinXP with unzip
> 5.50 and GNU Awk 3.1.4.
Versions don't matter in this case as no awk would have access to the file name
passed to the previous command in the pipe that was generating the input stream
that awk sees.
Your best bet is to use an awk variable, e.g.:
unzip -p data1990.zip | gawk -v filename="data1990.zip" 'END { print filename }'
Ed.
| |
| Roland Rau 2008-01-18, 6:59 pm |
| Ed Morton wrote:
>
>
> Your best bet is to use an awk variable, e.g.:
>
> unzip -p data1990.zip | gawk -v filename="data1990.zip" 'END { print filename }'
>
Thank you very much for your fast answer. I will try that.
All the best,
Roland
|
|
|
|
|