LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-22-2012, 01:08 PM   #1
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Rep: Reputation: Disabled
command to display a part of the file


Hi all,

Is there any way that i can display a portion of the file ?
For example, i can find a word in the file using "grep" but i want to display all lines in a file after the word that i just grep'ed for ?

sorry if my explanation is confusing.

Thanks in advance!
 
Old 03-22-2012, 01:27 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,355

Rep: Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989
The -A option in grep will print N lines after the match. It's a bit of a hack, but
Code:
grep -A 999999999 word file.txt
will print up to a billion lines after the matching line until it hits the EOF.

Last edited by suicidaleggroll; 03-22-2012 at 01:30 PM.
 
1 members found this post helpful.
Old 03-22-2012, 01:27 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
The exact answer depends somewhat on the exact nature of your data. If you gave us an example of the text we could give more detailed help.


grep has a -A (after) option for printing a number of lines after the match, but it has to be given a fixed value. There are also -B and -C ("before" and "context" ) options to print lines before and on both sides of the match.

More generally, sed can be given an address range to match a line, and print from there to the end of the file.

Code:
sed -n '/pattern/,$ p'
Here are a few useful sed references.
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/grabbag/
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt
 
1 members found this post helpful.
Old 03-22-2012, 01:42 PM   #4
ac_kumar
Member
 
Registered: Aug 2011
Distribution: Ubuntu, Fedora
Posts: 175

Rep: Reputation: 9
grep -A 5 "Pattern" file
grep tutorial:-
http://www.devdaily.com/unix/edu/examples/grep.shtml
 
1 members found this post helpful.
Old 03-22-2012, 03:18 PM   #5
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Wow!.....thanks everyone
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Take part of a Linux command line from a file eddyq Programming 9 01-14-2012 02:12 AM
[SOLVED] Display True file size using ls -l command in CentOS dmchenry Linux - Newbie 3 04-20-2011 08:47 AM
Problem in read a text file and display in DOS command... steve2688 Programming 7 06-17-2009 04:04 AM
Which command will use to display all .php file have size bigger than 30kb niitpro Linux - Newbie 3 09-09-2007 09:38 AM
long listing using ls -l command display year or time of the file mnd_world Linux - Newbie 1 05-20-2004 12:39 PM


All times are GMT -5. The time now is 11:09 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration