Help with tail command | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Help with tail command

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-04-2010
jagadish_gaddam jagadish_gaddam is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 13 January 2011, 11:43 AM EST
Posts: 25
Thanks: 1
Thanked 0 Times in 0 Posts
Java Help with tail command

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


Code:
#!/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
Code:
tail: cannot open input

could you pl suggeest me the right way to use it.

quick reply much appriciated!

Many thanks in advance

Last edited by pludi; 02-05-2010 at 01:17 AM.. Reason: code tags, please...
Sponsored Links
    #2  
Old Unix and Linux 02-05-2010
trey85stang trey85stang is offline
Registered User
 
Join Date: May 2008
Last Activity: 13 June 2012, 11:26 AM EDT
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
hmm.. whats in Tempfile?
Sponsored Links
    #3  
Old Unix and Linux 02-05-2010
amitranjansahu's Unix or Linux Image
amitranjansahu amitranjansahu is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 6 February 2014, 9:06 AM EST
Location: Bangalore,INDIA
Posts: 507
Thanks: 4
Thanked 27 Times in 27 Posts
try This


Code:
Filename=`cat /home/gaddamja/Tempfile |tail -"$Count" | head -1`

    #4  
Old Unix and Linux 02-05-2010
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 12 February 2015, 7:41 PM EST
Posts: 6,397
Thanks: 288
Thanked 674 Times in 643 Posts
What is the output from these two commands:


Code:
file /home/gaddamja/Tempfile

sed -n l /home/gaddamja/Tempfile

As suggested above there is something funny about that file.
Sponsored Links
    #5  
Old Unix and Linux 02-05-2010
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 1 April 2015, 5:35 AM EDT
Location: The Netherlands
Posts: 7,730
Thanks: 128
Thanked 544 Times in 512 Posts
There are some imperfections in your script, try this one:


Code:
#!/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"


Last edited by Franklin52; 02-05-2010 at 11:35 AM..
Sponsored Links
    #6  
Old Unix and Linux 02-05-2010
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 12 February 2015, 7:41 PM EST
Posts: 6,397
Thanks: 288
Thanked 674 Times in 643 Posts
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".

Last edited by methyl; 02-05-2010 at 11:47 AM..
Sponsored Links
    #7  
Old Unix and Linux 02-05-2010
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 1 April 2015, 5:35 AM EDT
Location: The Netherlands
Posts: 7,730
Thanks: 128
Thanked 544 Times in 512 Posts
Quote:
Originally Posted by methyl View Post
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.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Tail command in one line saurabh84g Solaris 4 10-15-2008 07:26 AM
tail command.. amon Shell Programming and Scripting 2 06-02-2006 04:36 AM
tail command whatisthis Shell Programming and Scripting 3 03-31-2005 08:34 AM
help with !(tail -2) command.. using pipes sdlayeeq UNIX for Advanced & Expert Users 8 02-17-2005 02:46 AM
tail command in SUN & HP_unix clemeot UNIX for Dummies Questions & Answers 3 05-08-2002 11:31 AM



All times are GMT -4. The time now is 03:48 AM.