The UNIX and Linux Forums  
Hello and Welcome from to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-20-2006
nortypig nortypig is offline
Registered User
  
 

Join Date: Aug 2006
Location: Hobart Tasmania
Posts: 58
Line works in solo but not in program?

Now I am just getting frustrated and confused... if anyone has some advice on how this anomoly is occurring I would greatly appreciate it.

Code:
cat helpme.txt | awk 'NR<5{printf("%-20s %-20d %-20d %-20.1f\n","hello",$1,$2,$3)}' | sort -rk4
This line works fine in solo - reads the three fields from helpme.txt and adds a first field "hello" before the others on output... seems simple enough and it works fine on its own on the command line.

In a small program it doesn't work...

Code:
#!/bin/sh

echo "Please enter the file you want compressed: \c"; read filename 

echo File: $filename

# check to see file exists and is readable with -r
if [ -r $filename ]
then

echo gzip | gzip -f $filename; gunzip -l $filename.gz > $filename.txt; gunzip $filename
gzip -f rose.bmp; gunzip -l rose.bmp.gz >> $filename.txt; gunzip rose.bmp.gz

cat helpme.txt | awk 'NR<5{printf("%-20s %-20d %-20d %-20.1f\n","hello",$1,$2,$3)}' | sort -rk4

else

echo sorry the file does not exist or is not readable

fi
So at this point I am thinking magic?

And yes with only the three fields in the short program it does work fine.