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

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Help with tail command

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 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 02-05-2010
amitranjansahu's Avatar
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 02-05-2010
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 673 Times in 642 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 02-05-2010
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 30 October 2014, 12:48 PM EDT
Location: The Netherlands
Posts: 7,719
Thanks: 123
Thanked 538 Times in 508 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 02-05-2010
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 673 Times in 642 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 02-05-2010
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 30 October 2014, 12:48 PM EDT
Location: The Netherlands
Posts: 7,719
Thanks: 123
Thanked 538 Times in 508 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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:08 AM.