[net.sources] YASS

aims@ssc-vax.UUCP (John Daley) (03/10/86)

This is a 'simple' little shell script I whipped up, out of need, to
print a specific line of a specific file.  Yes, I chose to use the B
shell, but it gets the job done, right?.

Why am I posting such a meager little script?  This newsgroup hasn't
been very active lately (excluding discussions).  Anybody out there
got a better way to do what my script does?

Any tips on error-trapping?  Any good scripts out there?  Hello?

--- CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE ---

#!/bin/sh
# 
#         Script: /usr/local/line
# 
#         Author: Ray E. Saddler III
#                 Ballistic Systems Division
#                 Computer Aided Design Support and Administration
#                 Boeing Aerospace Company Scientific Systems
# 
#        Created: 86-03-10 Ray
# 
#       Enhanced: YY-MM-DD XYZ
# 
#        Purpose: Print a specified line of a specified file.
# 
#########1#########2#########3#########4#########5#########6#########7#########8
# 
# Print opening messages - syntax check
# 
       while test $# -ne 2
         do
           case $1 in
             *)
               echo "Usage: line [line number] [file name]"
               exit 0
             continue
           esac
         continue
       done
# 
# If file ($2) does not exist - ABORT
# 
       if test -f $2
         then
           continue
         else
           echo "File: $2 not found"
           exit 0
         continue
       fi
# 
#  Delete scratch file: /tmp/LINE_COUNT if it exists
# 
       if test -f /tmp/LINE_COUNT
         then
           rm /tmp/LINE_COUNT
         else
           continue
         continue
       fi
# 
# Count how many lines exist in file ($2) - record in /tmp/LINE_COUNT
# 
       WORD_COUNT=`wc -l $2`
       for DATA in `echo $WORD_COUNT`
         do
           echo $DATA>>/tmp/LINE_COUNT
         continue
       done
# 
# Set LINE_COUNT buffer to the value of line #1 in file: /tmp/LINE_COUNT
# 
       LINE_COUNT=`head -1 /tmp/LINE_COUNT`
# 
# If the value of $1 exceeds the line count of $2 - ABORT
# 
       if [ $1 -gt $LINE_COUNT ]
         then
           echo "Unable to print line $1, $2 has only $LINE_COUNT lines."
           exit 0
         else
           continue
         continue
       fi
# 
# All systems go - find line $1 in file $2
#
       head -$1 $2 | tail -1
# 
# End of executable code
# 
#########1#########2#########3#########4#########5#########6#########7#########8


--- CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE --

(BTW - excluding error traps & comments this could be reduced to:

 head -$1 $2 | tail -1)

P.S.

Anybody out there gotta public domain program that graphically (sp?) displays
the status of a disk (i.e. available/used blocks/sectors etc?)

-- 

################################################################################
#  Ray E. Saddler III @ Boeing Aerospace Company - Ballistic Systems Division  #
#  Tech. Applications  CAD Support and Administration - BAC Scientfic Systems  #
#  Seattle, Washington (vacation spot of the stars) USA, Earth, lost in space  #
################################################################################

Disclaimer: The  Boeing  Company shall not be held responsible for damage caused
            by fire, in the event I should spontaneously (sp?) combust.  G'-day.

Quote: "" - unknown

jrv@siemens.UUCP (03/17/86)

How about:

	sed -n ${1}p ${2}


This will work for invocations such as  'line 25,30 file' to print lines
25 through 30 or for that matter any valid address ranges.

Jim Vallino
Siemens Research and Technology Lab.
Princeton, NJ
{allegra,ihnp4}!princeton!siemens!jrv