|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
hmm.. whats in Tempfile?
|
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
try This Code:
Filename=`cat /home/gaddamja/Tempfile |tail -"$Count" | head -1` |
|
#4
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|