The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extract particular text Shell_Learner Shell Programming and Scripting 4 04-24-2009 05:51 AM
c program to extract text between two delimiters from some text file kukretiabhi13 High Level Programming 7 12-03-2008 06:29 PM
Using awk to extract text Davizzle Shell Programming and Scripting 5 08-15-2008 01:09 AM
Sorting rules on a text section Indalecio Shell Programming and Scripting 4 12-05-2006 05:25 AM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 02:50 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-02-2009
meny meny is offline
Registered User
  
 

Join Date: Jul 2009
Location: Israel
Posts: 5
how can i extract text section via grep

hi, i have a very long text file. i need to extract with grep command a certain part.
for example text file include 1ooo rows:
1....
2...
3...
.
.
.
1000

i want to view with grep only rows 50-100.
any ideas will be appreciated
thanks...
  #2 (permalink)  
Old 07-02-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
why you want to do it with grep only??
sed,awk many other simple commands can do it.. read the man pages and give it a try..
  #3 (permalink)  
Old 07-02-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
Hi.

Grep is for searching for specific things. If you only want specific lines, not based on the contents you could, amongst other things, use head and tail..

Code:
head -100 file | tail -50
  #4 (permalink)  
Old 07-02-2009
meny meny is offline
Registered User
  
 

Join Date: Jul 2009
Location: Israel
Posts: 5
thanks mate, in order to use your solution i need another piece of the puzzle:
lets say that i know the first row number (e.g. 50) but i need to find out the number of the bigger one. the only clue i have is that row 100 is starting with certain string (x).
between 50-100 x appears only on the 100 row, though after 100 it appears on various rows. do you have an idea how can i locate the number of that row?
-----------------------------------------------------------------------
BTW i need this section for manipulating it in my bash script...
if you can help it will be highly appreciated.
  #5 (permalink)  
Old 07-02-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
nawk 'FNR==50,/^x/' myFile
  #6 (permalink)  
Old 07-02-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
Yep, that's good!

And by the same definition, so is

Code:
awk 'FNR==50,FNR==100' myFile
I do love this forum!
  #7 (permalink)  
Old 07-02-2009
meny meny is offline
Registered User
  
 

Join Date: Jul 2009
Location: Israel
Posts: 5
thanks guys

thanks folks but it seems the it just opens the file (as cat).

hoped it will retrieve the row's number.

thanks...
Sponsored Links
Reply

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0