Substitute File name

Hi all
I am in a small problem pl help me out.
I am having a directory having ZIP files with name starting as :
01.xyz
02.pqr
and so on
I want to run the script-
cat myfile | awk '{print $1, $2}' | while read var1 var2
do
zcat $var2* | grep "^000$var1" >> my_output
done
Where the myfile contains like :
1231231 01
1451515 02
i.e. I want to substitute the var2 for ZIP files in the directory and then search the var1 in that file. But It gives error *.Z : no such file or directory.
Please help me out.
Thanks in advance.

Hi,
Did you miss the extension after the var2...
do
zcat $var2*.zip | grep "^000$var1" >> my_output
done

Because i was able to do the same successfully.
Thanks
Raghuram

I tried with extension also but it does not work and gives the same error. Moreover i think attaching the extension will not make any difference.

One question...

Are you sure the files are with extension .zip? or .gz?

cat myfile | awk '{print $1, $2}' | while read var1 var2
do
zcat $var2*.gz | grep "^000$var1" >> my_output
done

Files are with ext .Z ( must be zip files created using compress command)
trying *.Z or *.gz not working. Where is the error???

First simplify your code removing unnecessary commands -

while read var1 var2 
do
zcat ${var2}* | grep "^000$var1" >> my_output
done <myfile

Check if it works. Didnt have time to simulate it. :). Make sure you are in the same directory as the zip files. Otherwise, your 'myfile' should contain the path or you should hardcode the path.

When you use:
zcat $var2* | grep "^000$var1" >> my_output

It is actually translated to something like this:

zcat 01* | grep ....

So, there is the issue.

If you know that your $var2 contains the exact file name, then remove the "*". Use

zcat $var2 | grep "^000$var1" >> my_output

You can also use the file extension to be safe i.e "zcat $var2.zip".

Or if $var2 doesn't contain the exact file name then try using double quotes around $var*. Like

zcat "$var2*" | grep "^000$var1" >> my_output

Hope this helps.

Dear friend
Already tried all these. But all in vain. Folder contains the files starting with 01.xxxx, 02.xxxxxfg etc some I have to use *. But all attempts fails. Any other Way to do.

Thanks for trying,
But it does not worked and gave the same error. I have already checked the file names and path etc. No mistake in it. But why it is not replacing zcat $var2* with zcat 01* is not understood. Some other suggestions pl.
Thanks

what shell are you using. I am using bash and this syntax works

# var=01
# zcat ${var}*

zcat: 01test.gz: not in gzip format

As you can see, it is able to detect files starting with 01. Also, zcat will complain if your extension is not .gz ..

dear friend
is is still not working
Unix Gurus please help me for this script.....

show your code, error outputs and whatever info that's will help us to help you.

I simulated your error and the only time this error occurs is when there are no files of type .Z in the directory where I am searching for the *.Z files. The script that I ran was a part of your code.

/home/nayakr/ranj/unix_forum> cat chkfile.sh
while read var1 var2
do
zcat tmp/$var2* | grep 'junk' >>myoutfile
done <myfile

There was 'tmp' directory with no *.Z files.

/home/nayakr/ranj/unix_forum/tmp> ls -l
total 0
/home/nayakr/ranj/unix_forum/tmp> 

The content of myfile was

/home/nayakr/ranj/unix_forum> cat myfile
pattern testfile

/home/nayakr/ranj/unix_forum>

Note that, the file contained a newline at the end. On running the script,

/home/nayakr/ranj/unix_forum> chkfile.sh
tmp/testfile*.Z: A file or directory in the path name does not exist.
tmp/*.Z: A file or directory in the path name does not exist.

Hope that answers your question.

The code I am trying is :
cat myfile | awk '{print $1, $2}' | while read var1 var2
do
zcat $var2* | grep "^000$var1" >> my_output
done
where myfile contains data like :
1231231 01
1451515 02
I just want to replace the var2 i.e. 01 with the zip files (.Z files) starting with 01.abcdfef
01.hjjjkjhjh and so on and then grep the var1 from these files.
Error I am getting is :
*.Z : No such file or directory.
*.Z : No such file or directory.
*.Z : No such file or directory.
*.Z : No such file or directory.
.
.
.
.
I am not getting how to substitute the file names read as var2 of myfile. Please help...

It seems to me that you don't actually have .Z files in your directory, as indicated by the error you got. can you show a listing of what is currently in your directory?

Why not put

set -vx 

at the beginning of the script and see what is happening. May the the contents from the file is not being read into the variables properly.

Here Is the long listing :
total 4966860
-rw-r--r-- 1 oracle dba 573694919 Jan 21 2006 01.det_26dec_10jan06
-rw-r--r-- 1 oracle dba 106617087 Jan 30 2006 01a.det_11_25jan06.Z
-rw-r--r-- 1 oracle dba 115342143 Feb 14 2006 02.det_26jan_10feb06.Z
-rw-r--r-- 1 oracle dba 104965439 Feb 28 2006 02a.det_11_25feb06.Z
-rw-r--r-- 1 oracle dba 91796895 Mar 18 2006 03.det_26feb_10mar06.Z
-rw-r--r-- 1 oracle dba 136879104 Apr 4 2006 03a.det_11_31mar06.Z
-rw-r--r-- 1 oracle dba 96888889 Apr 18 2006 04.det_01_15apr06.Z
-rw-r--r-- 1 oracle dba 92467706 May 2 2006 04a.det_16_30apr06.Z
-rw-r--r-- 1 oracle dba 92596770 May 19 2006 05.det_01_15may06.Z
-rw-r--r-- 1 oracle dba 93294139 Jun 2 2006 05a.det_16_31may06.Z
-rw-r--r-- 1 oracle dba 84315109 Jun 19 2006 06.det_01_15june06.Z
-rw-r--r-- 1 oracle dba 82132177 Jul 3 2006 06a.det_16_30june06.Z
-rw-r--r-- 1 oracle dba 81434327 Jul 17 2006 07.det_01_15july06.Z
-rw-r--r-- 1 oracle dba 83665061 Aug 8 2006 07a.det_16_31july06.Z
-rw-r--r-- 1 oracle dba 74758692 Aug 19 2006 08.det_01_15aug06.Z
-rw-r--r-- 1 oracle dba 80815415 Sep 2 2006 08a.det_16_31aug06.Z
-rw-r--r-- 1 oracle dba 75974892 Sep 16 13:36 09.det_01_15sep06.Z
-rw-r--r-- 1 oracle dba 73488779 Oct 4 15:16 09a.det_16_30sep06.Z
-rw-r--r-- 1 oracle dba 69199285 Oct 17 11:42 10.det_01_15oct06.Z
-rw-r--r-- 1 oracle dba 70560621 Nov 3 09:01 10a.det_16_31oct06.Z
-rw-r--r-- 1 oracle dba 67741625 Nov 16 15:47 11.det_01_15nov06.Z
-rw-r--r-- 1 oracle dba 64394867 Dec 1 10:52 11a.det_16_30nov06.Z
-rw-r--r-- 1 oracle dba 62518866 Dec 16 12:30 12.det_01_15dec06.Z
-rw-r--r-- 1 oracle dba 64592095 Jan 1 10:15 12a.det_16_31dec06.Z

Here is the output after set -vx
cat 2006cases | awk '{print $1,$2}' | while read var1 var2
cat 2006cases | awk '{print $1,$2}' | while read var1 var2
> do
do
> zcat $var2*.Z | grep "^00011$var1" >> output
zcat $var2*.Z | grep "^00011$var1" >> output
> done
done
+ cat 2006cases
+ awk {print $1,$2}
+ read var1 var2
*.Z at 01
*.Z: No such file or directory
+ grep ^0001120093878
+ read var1 var2
*.Z at 01
*.Z: No such file or directory
+ grep ^0001120901190
+ read var1 var2
*.Z at 01
*.Z: No such file or directory
+ grep ^0001120004616
+ read var1 var2
*.Z at 01
*.Z: No such file or directory
+ grep ^0001120004648
+ read var1 var2
+ grep ^0001120005124
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005157
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005163
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120010938
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120026220
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120039617
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120055789
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120074845
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120563414
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120908313
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120908355
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120908355
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120908868
*.Z at 01
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005124
*.Z at 02
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005177
*.Z at 02
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005225
*.Z at 02
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005269
*.Z at 02
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005277
*.Z at 02
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120073065
*.Z at 02
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120563414
*.Z at 02
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120567427
*.Z at 02
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005528
*.Z at 03
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005550
*.Z at 03
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005558
*.Z at 03
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120005562
*.Z at 03
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120047199
*.Z at 03
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120049280
*.Z at 03
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120069616
*.Z at 03
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120090604
*.Z at 04
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120098202
*.Z at 08
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120065833
*.Z at 10
*.Z: No such file or directory
+ read var1 var2
+ grep ^0001120900330
*.Z at 11
*.Z: No such file or directory
+ read var1 var2

Paste the top 10 lines of '2006cases' file.

Thanks.

20093878 01
20901190 01
20004616 01
20004648 01
20005124 01
20005157 01
20005163 01
20010938 01
20026220 01
20039617 01
20055789 01
20074845 01
20563414 01
20908313 01
20908355 01
20908355 01
20908868 01
20005124 02
20005177 02
20005225 02
20005269 02
20005277 02
20073065 02
20563414 02
20567427 02
20005528 03
20005550 03
20005558 03
20005562 03