UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 27th, 2008, 11:16 AM
fubes2000's Avatar
fubes2000 fubes2000 is offline
manwich
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canadanistan
Posts: 295 fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)  Folding Points: 79002 Folding Title: Intermediate FolderFolding Points: 79002 Folding Title: Intermediate FolderFolding Points: 79002 Folding Title: Intermediate FolderFolding Points: 79002 Folding Title: Intermediate Folder
Time spent in forums: 3 Days 11 h 19 m 40 sec
Reputation Power: 158
Send a message via AIM to fubes2000
Display certain range of lines in a file

I'm working on a script to reduce the work needed to find a certain qmail log entry and display it in full, but I've hit a sticking point. After I've grep'd out all the relevant log entries to a temp file I want to be able to paginate them with line numbers, but I'm wondering if there's a better way to show lines X through Y in a file.

I say a 'better' way because at the moment the only way I can think of is to calculate the position of X and Y relative to the start or end of the file an then head | tail the file, but the logic gets a bit sticky depending on finnicky little things like 0 or 1 based indexes. I know there should be a simple way with sed or awk, but it escapes me.

TIA
__________________

Reply With Quote
  #2  
Old March 27th, 2008, 11:25 AM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 591 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 51 m 38 sec
Reputation Power: 100
Send a message via AIM to L7Sqr
awk sounds like a good idea if you know the indicies:
Code:
awk '{if(NR > X && NR < Y) {print}}' log_file
Where X and Y represent the lines 'from' and 'to' in the file.
__________________
-- I'll provide you with reference points; if they dont work, refer to something else.

If you process text, this might make your life a little easier.

Reply With Quote
  #3  
Old March 27th, 2008, 11:32 AM
fubes2000's Avatar
fubes2000 fubes2000 is offline
manwich
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canadanistan
Posts: 295 fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)fubes2000 User rank is First Lieutenant (10000 - 20000 Reputation Level)  Folding Points: 79002 Folding Title: Intermediate FolderFolding Points: 79002 Folding Title: Intermediate FolderFolding Points: 79002 Folding Title: Intermediate FolderFolding Points: 79002 Folding Title: Intermediate Folder
Time spent in forums: 3 Days 11 h 19 m 40 sec
Reputation Power: 158
Send a message via AIM to fubes2000
Wow, thanks for the quick response!

I wish I had thought of that sooner since I should be able to use what you're given me to do nearly everything in one awk program.

Thanks again.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Display certain range of lines in a file


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway