how to retreive a block of data from the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to retreive a block of data from the file
# 1  
Old 06-26-2008
how to retreive a block of data from the file

Hi
I am running a 'grep' command to retrieve a line from the file. The problem is that I also need 21 lines which go right after the line I just 'grep'(ed)
Is there a way to retrieve this block of data? Thanks -A
# 2  
Old 06-26-2008
Code:
awk '/pattern/{c=21;next}c&&c--' file

Regards
# 3  
Old 06-26-2008
awk command fails

Hi
I am trying to retreive the line containing the pattern from a file and 21 lines right after this number by running the following awk command:
$ awk '/940/{c=21;next}c&&c--' allocations.ini and getting the following
syntax error:

$ awk '/940/{c=21;next}c&&c--' allocations.ini
awk: syntax error near line 1
awk: bailing out near line 1
$

any idea? Thanks -A
# 4  
Old 06-26-2008
On Solaris use nawk.
# 5  
Old 06-26-2008
Quote:
Originally Posted by aoussenko
Hi
I am trying to retreive the line containing the pattern from a file and 21 lines right after this number by running the following awk command:
$ awk '/940/{c=21;next}c&&c--' allocations.ini and getting the following
syntax error:

$ awk '/940/{c=21;next}c&&c--' allocations.ini
awk: syntax error near line 1
awk: bailing out near line 1
$

any idea? Thanks -A
also if you need to include the line containing a pattern:
Code:
nawk '/pattern/{c=22}c&&c--' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grab a block of data in a file with repeating pattern?

I need to send email to receipient in each block of data in a file which has the sender address under TO and just send that block of data where it ends as COMPANY. I tried to work this out by getting line numbers of the string HELLO but unable to grab the next block of data to send the next... (5 Replies)
Discussion started by: loggedout
5 Replies

2. Shell Programming and Scripting

Retreive data with arrangement

Hi all I have following part of a big file TTDS00002 Synonyms M1 receptor TTDS00002 Disease Alzheimer's disease TTDS00002 Disease Bronchospasm (histamine induced) TTDS00002 Disease Cognitive deficits TTDS00002 Disease Schizophrenia TTDS00002 Function The muscarinic acetylcholine... (2 Replies)
Discussion started by: kareena
2 Replies

3. Solaris

Retreive deleted file name if you having inode number

Some one please help me to find deleted file name, if I am having inode number in Solaris without using any 3rd party tool. Thanks :) (3 Replies)
Discussion started by: aksijain
3 Replies

4. Shell Programming and Scripting

Selecting A Block Of Data From A File (AWK)

Ladles and Jellyspoons,I am trying to use, unsucessfully I might add, awk to strip a large block of information from and audit output.The format resembles the following:-----------------------------------------------------------Event: execveTime: ... (3 Replies)
Discussion started by: proc1269
3 Replies

5. Linux

Increasing total data size per file system request for block drivers

Hi All, I am writing a block driver for a 2GB SD card where i get the total amount of data per request as follows: struct request *req; uint card_addr,total_bytes; struct request_queue *rq = BlkDev->queue; req = elv_next_request(rq); .. .. card_addr = req->sector*512;... (1 Reply)
Discussion started by: amio
1 Replies

6. UNIX for Dummies Questions & Answers

How to cut data block from .txt file in shell scripting

Hi All, Currently i have to write a script. For which i need to cut a block from .txt file. I know the specific word that starts the block and ends the block. Can we do it in shell scripting..? Please suggest.... (6 Replies)
Discussion started by: pank29
6 Replies

7. Shell Programming and Scripting

how to retreive a block of data from the file

Hi I have a several thousands lines text file. Is there any command(s), which would allow me to retreive a block of data between two specified lines of this file? Thanks a lot -A (2 Replies)
Discussion started by: aoussenko
2 Replies

8. Shell Programming and Scripting

Retreive content between specific lines ina file

Hi I have a text file which has two sets of lines repeating for "n" number of times.Some data is printed between the two lines.I want to retrieve all the data thats there in between those two set of lines.I have the string value of those two set of lines. To be much more clearer ... (4 Replies)
Discussion started by: chennaitomcruis
4 Replies

9. Shell Programming and Scripting

urgent-extracting block data from flat file using shell script

Hi, I want to extract block of data from flat file. the data will be like this start of log One two three end of log i want all data between start of log to end of log i.e One two three to be copied to another file. This particular block may appear multiple times in same file. I... (4 Replies)
Discussion started by: shirish_cd
4 Replies

10. Shell Programming and Scripting

Parsing file and extracting the useful data block

Greetings All!! I have a very peculiar problem where I have to parse a big text file and extract useful data out of it with starting and ending block pattern matching. e.g. I have a input file like this: sample data block1 sample data start useful data end sample data block2 sample... (5 Replies)
Discussion started by: arminder
5 Replies
Login or Register to Ask a Question