Hi All,
My query seems to be silly but Iam unable to find where the exact problem lies.
I have a script to unzip set of files
here is the script
#!/bin/ksh
Count=`cat /home/gaddamja/Tempfile | wc -l`
while [ $count -ge 1 ]
do
Filename=`cat /home/gaddamja/Tempfile |tail -$Count | head -1`
cd /home/gaddamja/FilesDirectory
`gunzip $Filename`
echo " $Filename unzipped successfully"
$Count=`expr $count - 1`
done
echo "Unzipping completed"
from second line I am getting the count but in 5th line when i use 'Count' with tail its not working
it says
tail: cannot open input
could you pl suggeest me the right way to use it.
quick reply much appriciated!
Many thanks in advance
try This
Filename=`cat /home/gaddamja/Tempfile |tail -"$Count" | head -1`
methyl
February 5, 2010, 10:37am
4
What is the output from these two commands:
file /home/gaddamja/Tempfile
sed -n l /home/gaddamja/Tempfile
As suggested above there is something funny about that file.
There are some imperfections in your script, try this one:
#!/bin/ksh
count=$(wc -l < /home/gaddamja/Tempfile)
cd /home/gaddamja/FilesDirectory
while [ $count -ge 1 ]
do
Filename=$(tail -$count /home/gaddamja/Tempfile | head -1)
gunzip $Filename
echo " $Filename unzipped successfully"
count=$(($count - 1))
done
echo "Unzipping completed"
methyl
February 5, 2010, 11:39am
6
Interestingly franklin52 version should generate the same error because $Count is empty at the time of the "tail" command thereby causing "tail - ". Update: franklin52 version now has $count and therefore does not have the problem in that form.
What is weird is why $Count is empty (or has a leading space character) in the original script also causing "tail - ".
Hmm. In many old scripts I have a sed to remove a spurious space character from the output of "wc -l".
methyl:
Interestingly franklin52 version should generate the same error because $Count is empty at the time of the "tail" command thereby causing "tail - ". Update: franklin52 version now has $count and therefore does not have the problem in that form.
What is weird is why $Count is empty (or has a leading space character) in the original script also causing "tail - ".
Hmm. In many old scripts I have a sed to remove a spurious space character from the output of "wc -l".
The problem is that he's using $count and $Count interchangeably.
methyl
February 5, 2010, 12:22pm
8
I could only find one simple way to generate the error message "tail: cannot open input".
echo "hello"|tail -1
hello
echo "hello"|tail - 1
tail: cannot open input
error: No such file or directory on file -
There were many other issues in the script.