LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-13-2003, 03:02 AM   #1
ganninu
Member
 
Registered: Jul 2003
Distribution: RH 7.3/8.0/9.0, Debian Stable 3.0, FreeBSD 5.2, Solaris 8/9/10,HP-UX
Posts: 340

Rep: Reputation: 30
Display/Read line 'N' in a text file using script


I was just wondering if there exists already an inbuilt Linux command to just display a particular line or range of lines in a text file. I normally use a "for" loop for this kind of thing and works well.
 
Old 10-13-2003, 05:20 AM   #2
iainr
Member
 
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Rep: Reputation: 30
There may be a more elegant way, but if, for example, I wanted to display lines 23-30 I would use

head -30 <file> | tail -8

Or more generally, in a script

FIRST_LINE=$1
LAST_LINE=$2
typeset -i NUM_LINES=$LAST_LINE-$FIRST_LINE+1
head -$LAST_LINE|tail -$NUM_LINES

(I only just tried this code in ksh so apologies if it needs to be tweaked for bash).

Iain.
 
Old 10-13-2003, 05:28 AM   #3
ganninu
Member
 
Registered: Jul 2003
Distribution: RH 7.3/8.0/9.0, Debian Stable 3.0, FreeBSD 5.2, Solaris 8/9/10,HP-UX
Posts: 340

Original Poster
Rep: Reputation: 30
very elegant technique indeed...
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 06:07 PM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 08:51 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM
Script to read a simple text file ravykanth Linux - Newbie 9 10-22-2003 04:15 AM
[C & Linux] Read line from text-file Y_Haarman Programming 5 11-08-2002 04:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration