how can i extract text section via grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how can i extract text section via grep
# 1  
Old 07-02-2009
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  
Old 07-02-2009
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  
Old 07-02-2009
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  
Old 07-02-2009
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  
Old 07-02-2009
Code:
nawk 'FNR==50,/^x/' myFile

# 6  
Old 07-02-2009
Yep, that's good!

And by the same definition, so is

Code:
awk 'FNR==50,FNR==100' myFile

I do love this forum!
# 7  
Old 07-02-2009
thanks guys

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

hoped it will retrieve the row's number.

thanks...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need grep regex to extract multiline text between two strings

I have a file conatining the below: --- 10.9.16.116: /tmp/5835113081224811756.jar: hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb /tmp/4603745991442278706.jar: hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb 10.9.14.126: /tmp/conf/extra/httpd-ssl.conf: hash:... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

How to Grep of by section?

I have a script that outputs this as a file John Smith ---------------- memberOf: example1;sampletest;test memberOf: example2;sampletest;test memberOf: example3;sampletest;test memberOf: example4;sampletest;test A Member of 4 Groups Sally Smith ---------------- memberOf:... (4 Replies)
Discussion started by: ajetangay
4 Replies

3. Shell Programming and Scripting

Script extract text from txt file with grep

All, I require a script that grabs some text from the gitHub API and will grep (or other function) for a string a characters that starts with (") quotes followed by two letters, may contain a pipe |, and ending with ) . What i have so far is below but it's not returning anything. ... (4 Replies)
Discussion started by: ChocoTaco
4 Replies

4. Shell Programming and Scripting

Grep text and see all section

Hello I am looking for a way to look in files and to grep text and see the all section of the text ! Sharon123 deed 10000 class 360 ! sharon456 2000 deed ! Sharon789 live 3000 ! To grep "deed "an see the all section (5 Replies)
Discussion started by: sharong
5 Replies

5. Shell Programming and Scripting

Extract record from file based on section.

input file output file (1 Reply)
Discussion started by: lathigara
1 Replies

6. Shell Programming and Scripting

Extracting text from within a section of text using AWK

I have a command which returns the below output. How can I write a script to extract mainhost and secondhost from this output and put it into an array? I may sometimes have more hosts like thirdhost. I am redirecting this output to a variable. So I guess there should be a awk or sed command to... (7 Replies)
Discussion started by: heykiran
7 Replies

7. Shell Programming and Scripting

Need help please with Grep/Sed command to extract text and numbers from a file

Hello All, I need to extract lines from a file that contains ALPHANUMERIC and the length of Alphanumeric is set to 16. I have pasted the sample of the lines from the text file that I have created. My problem is that sometimes 16 appears in other part of the line. I'm only interested to... (14 Replies)
Discussion started by: mnassiri
14 Replies

8. Shell Programming and Scripting

Extract section of file based on word in section

I have a list of Servers in no particular order as follows: virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection). 9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
Discussion started by: jelloir
2 Replies

9. UNIX for Advanced & Expert Users

bash/grep/awk/sed: How to extract every appearance of text between two specific strings

I have a text wich looks like this: clid=2 cid=6 client_database_id=35 client_nickname=Peter client_type=0|clid=3 cid=22 client_database_id=57 client_nickname=Paul client_type=0|clid=5 cid=22 client_database_id=7 client_nickname=Mary client_type=0|clid=6 cid=22 client_database_id=6... (3 Replies)
Discussion started by: Pioneer1976
3 Replies

10. Shell Programming and Scripting

Search and extract by section from configuration

Hi, I understand either AWK or SED can do this, but I not sure how to extract the following configuration in section. Meaning when I need to find code with " ip helper-address 192.168.11.2" , it would start from "interface Serial0/0" and "interface FastEthernet0/1". Only displaying both section... (2 Replies)
Discussion started by: haphazard
2 Replies
Login or Register to Ask a Question