Hi Guys,
I am using a script to insert a record count on the top of a text file.
But now the source file has changed and the new files are in a compressed format. So I will have to uncompress each file
attach the record count as header and compress it back.
I tried to do something like this. But this script will fail when it reaches line # 7 as variable 'file' will already be assigned a name with extension .Z in line # 6.
How do i overcome this.
Thanks,
N.
1. for file in x[0-9].dat.Z
2. do
3. uncompress file
4. lines=`printf "$(wc -l < ${file} )"`
5. ( echo "$lines" ; cat $file )>tmp$$
6. mv tmp$$ $file
7. compress $file
8. done
I am using a script to insert a record count on the top of a text file.
But now the source file has changed and the new files are in a compressed format. So I will have to uncompress each file
attach the record count as header and compress it back.
I tried to do something like this. But this script will fail when it reaches line # 7 as variable 'file' will already be assigned a name with extension .Z in line # 6.
How do i overcome this.
Thanks,
N.
1. for file in x[0-9].dat.Z
2. do
3. uncompress file
4. lines=`printf "$(wc -l < ${file} )"`
5. ( echo "$lines" ; cat $file )>tmp$$
6. mv tmp$$ $file
7. compress $file
8. done