LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-19-2009, 02:57 PM   #1
quadmore
LQ Newbie
 
Registered: May 2004
Location: Ottawa, Ontario, Canada
Distribution: Redhat 9
Posts: 20

Rep: Reputation: 0
bash : read every line from text file starting at given line number


Hello,

I have a complicated parsing script.

Say my parameter is line number 200. I know my file has more lines than the given parameter.

head -c 200 filename
would give me the first 200 which is not what I need.

What I need is every line starting at line number 200.

I was hoping not to have to nest yet another loop.

TIA for all suggestions,

Bert
 
Old 02-19-2009, 03:15 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
sed -n '200,$p' textfile should work.

Note that the $ needs to be escaped or enclosed in single-quotes, or else your shell will interpret $p as if it were a variable.
 
Old 02-19-2009, 03:26 PM   #3
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Code:
tail -n+200 file
will give every line after (including) line 200 in file
 
Old 02-19-2009, 03:44 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
awk 'NR>=200' file
 
Old 02-20-2009, 12:29 PM   #5
quadmore
LQ Newbie
 
Registered: May 2004
Location: Ottawa, Ontario, Canada
Distribution: Redhat 9
Posts: 20

Original Poster
Rep: Reputation: 0
Smile Thank you very much

All three solutions work perfectly on my system, I tip my hat to you.

Thank you very much.

Cheers,
Bert
 
  


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 read a given line number from text bendeco13 Programming 7 08-31-2012 03:49 PM
I would like need a suggestion on bash shell : Read a file line by line and do stuff madi3d8 Linux - Newbie 1 01-15-2009 09:30 AM
bash - read or write to specific line in text file? babag Programming 11 08-23-2008 01:44 PM
help with c program to read each line from text file, split line , process and output gkoumantaris Programming 12 07-01-2008 12:38 PM
read line by line form text file in java. spank Programming 1 10-18-2006 02:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:45 AM.

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