|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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
__________________
|
|
#2
|
|||
|
|||
|
awk sounds like a good idea if you know the indicies:
Code:
awk '{if(NR > X && NR < Y) {print}}' log_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. |
|
#3
|
||||
|
||||
|
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. ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Display certain range of lines in a file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|