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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 08:29 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM
getting the line number by extracting a line bishweshwar Shell Programming and Scripting 2 08-04-2007 09:46 AM
Unix Script with line number at beginning of each line. mascorro Shell Programming and Scripting 5 06-19-2006 04:34 PM
delete a line based on first character of the line borncrazy UNIX for Dummies Questions & Answers 2 12-06-2005 03:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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
  #2 (permalink)  
Old 09-20-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,518
Code:
awk -F: '$3>500{print NR" " $0}' /etc/passwd
  #3 (permalink)  
Old 09-20-2007
narendra.pant narendra.pant is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 8
:)

thanks ,, yeah its workin ,, ,, i m gng to read bout awk now
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0