The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 09-20-2007
narendra.pant narendra.pant is offline
Registered User
 

Join Date: Sep 2007
Posts: 8
extracting a line based on line number

i want to cut all the entries from the /etc/passwd file in which the uid is> 500

for this i was writing this ,m quiet new to all this.. scripting

but on the 6th n 8th line ,, i hav to specify a line number .. to get the commnd working .. but i want to use variable i instead of that ,, which is not allowed ..

my problem is that ,, i have a variable i , which is being incremented n it is containing an integer value as u can c , now i want to print that line which is satisfying the if condition .


because i was not working so i wrote 56 instead of that , as in my passwd file it was havin pid >500 just to test ..







#!/bin/bash
nol=`wc -l /etc/passwd | cut -d " " -f 1`
i=1
if [ $nol -ge $i ]
then
if [ `sed -n '56p' /etc/passwd | cut -d \: -f 3` -ge 500 ]
then
sed -n '56p' /etc/passwd >hii
i=`expr $i + 1`
fi
fi
exit
Reply With Quote
Remove advertisements
!!
Forum Sponsor