The UNIX and Linux Forums  
Hello and Welcome from United States 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 -->
  #3 (permalink)  
Old 02-18-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
i prefer grep and sed to solve this problem.

Code:
a=`grep -n "bhargav" file1 | cut -d":" -f 1`
((b=a-1))
if test $b -ne 0
then
sed -n ""$b","$a"p" file1
else
sed -n '1 p' file1
fi