The UNIX and Linux Forums  


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 specific text and spaces to each line in a text file hertingm Shell Programming and Scripting 4 08-25-2008 03:34 PM
how to replace one line in text with several lines FunnyCats UNIX for Dummies Questions & Answers 1 01-18-2007 09:52 AM
how to print out line numbers of a text file? forevercalz Shell Programming and Scripting 4 12-12-2005 05:04 AM
Print only certain lines from a text file CamTu Shell Programming and Scripting 1 06-01-2005 12:47 PM
Search for text and print the next line alijassim Shell Programming and Scripting 2 08-17-2004 07:08 AM

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-16-2008
ram1729 ram1729 is offline
Registered User
  
 

Join Date: May 2008
Posts: 6
How to print the lines after 2nd line from text file

Hi All,

I need to print the lines after 2nd line irrespective of the number of lines in file

if the file contents are like below
----------
root:!:0:0::/root:/usr/bin/ksh
daemon:!:1:1::/etc:
bin:!:2:2::/bin:
sys:!:3:3::/usr/sys:
adm:!:4:4::/var/adm:
uucp:!:5:5::/usr/lib/uucp:
guest:!:100:100::/home/guest:
nobody:!:4294967294:4294967294::/:
lpd:!:9:4294967294::/:
.
.
.

I need from the line after "daemon" line like as below
-----
bin:!:2:2::/bin:
sys:!:3:3::/usr/sys:
adm:!:4:4::/var/adm:
uucp:!:5:5::/usr/lib/uucp:
guest:!:100:100::/home/guest:
nobody:!:4294967294:4294967294::/:
lpd:!:9:4294967294::/:
.
.
.
  #2 (permalink)  
Old 09-16-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,554
One way,
read the more man page. there's an option to start reading from certain line number.
  #3 (permalink)  
Old 09-16-2008
yogi_raj_143 yogi_raj_143 is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 16
there are many ways to do this...
I normally use sed for this,

sed -n '3,/ArbitWord/p' <inputFile>

here ArbitWord is something which you can not expect to be present in your input file

one other way is using tac

tac <inputFile> | head --lines=-2 | tac
  #4 (permalink)  
Old 09-16-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Or tail +3 /etc/passwd.
  #5 (permalink)  
Old 09-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The tail command is better in this scenario IMHO, but for completeness, you can use $ (meaning last line of file) instead of /ArbitWord/ in the sed script.
  #6 (permalink)  
Old 09-16-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,327
If the line number is unknown and you want to use a search pattern:


Code:
awk '/^daemon/{p=1}p' file

  #7 (permalink)  
Old 09-16-2008
ram1729 ram1729 is offline
Registered User
  
 

Join Date: May 2008
Posts: 6
Thank you for all for ur replays
tail +3 worling for my purpose
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 11:38 AM.


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