Extarct block data using awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extarct block data using awk
# 8  
Old 04-05-2016
Try
Code:
awk '
/Process Beginning/     {s = $0
                        }
/Process Ending/        {if (!FND) print s ORS $0
                         s = ""
                         FND = 0
                        }
/sqlExtract/            {FND = 1
                        }
' file
Process Beginning - 2016-04-02-00.36.13---->Print this line
Process Ending - 2016-04-02-00.36.36 -->Print this line

# 9  
Old 04-05-2016
If you also want to print the lines in between, you can use an address,address block in sed or awk
Code:
sed '/Process Beginning - 2016-04-02-10.01.20/,/Process Ending/!d' file

Code:
sed -n '/Process Beginning - 2016-04-02-10.01.20/,/Process Ending/p' file

Code:
awk '/Process Beginning - 2016-04-02-10.01.20/,/Process Ending/' file

For very big files it is more efficient to quit
Code:
sed -n '/Process Beginning - 2016-04-02-10.01.20/ {
 :L
 $!N
 /Process Ending/!b L
 p
 q
}
' file

Code:
awk '/Process Beginning - 2016-04-02-10.01.20/ {p=1} p; /Process Ending/ {exit}' file


Last edited by MadeInGermany; 04-05-2016 at 08:09 AM.. Reason: added a missing semicolon
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to print block of data

Hi All, Iam unable to print the below block and getting the error.Can anyone please help me in this. Input Data eaits001z$ echo "-------LINENO_JOBID_VAL--------${LINENO_JOBID_VAL}---" -------LINENO_JOBID_VAL--------58167|253473 58169|253473 58171|253473 58179|253473 58180|253473 58181|257311... (9 Replies)
Discussion started by: cskumar
9 Replies

2. Shell Programming and Scripting

awk --> math-operation in data-record and joining with second file data

Hi! I have a pretty complex job - at least for me! i have two csv-files with meassurement-data: fileA ...... (2 Replies)
Discussion started by: IMPe
2 Replies

3. Shell Programming and Scripting

Help with parsing data with awk , eliminating unwanted data

Experts , Below is the data: --- Physical volumes --- PV Name /dev/dsk/c1t2d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 8 PE Size (Mbytes) 8 Total PE 4350 Free PE 2036 Allocated PE 2314 Stale PE 0 IO Timeout (Seconds) default --- Physical volumes ---... (5 Replies)
Discussion started by: rveri
5 Replies

4. UNIX for Dummies Questions & Answers

Capture a block of data

Hi, I was trying a script to cature all data between 12-05-09 06:00:00 to 12-05-09 23:59:59 from a huge file. (i.e. Skip all data between 00:00:00 to 05:59:59) TOKEN-1 12-05-09 00:00:00 MAIPR no_OMDB_key #000995 > .. .. .. TOKEN-1 12-05-09 06:00:00 TRUNK 358 #04988 > .. .. TOKEN-1 12-05-09... (2 Replies)
Discussion started by: vanand420
2 Replies

5. 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

6. Shell Programming and Scripting

awk: How to search for a block within a block ?

Ok, I have some experience with awk, but I haven't touched it for years ... back again and I have one problem. I have large char file, it has hundreds of major text blocks. First, I need to grab and process those, and ignore everything else. That bit is simple. Within those major text... (5 Replies)
Discussion started by: DerekAsirvadem
5 Replies

7. Shell Programming and Scripting

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 (4 Replies)
Discussion started by: aoussenko
4 Replies

8. Shell Programming and Scripting

How can i extarct the output from a file which has been updated from last half an hou

hi, I have a log file , which is appending with current data i need the extarct which is updated from last 30 minutes the format of the date is Jun 18, 2008 8:59:18 AM how can i subtract 30 mins from the current date thanks Tarun. (5 Replies)
Discussion started by: tarundeepdhawan
5 Replies

9. Shell Programming and Scripting

to extarct data points

suppose u have a file which consist of many data points separated by asterisk Question is to extract third part in each line . 0.0002*0.003*-0.93939*0.0202*0.322*0.3332*0.2222*0.22020 0.003*0.3333*0.33322*-0.2220*0.3030*0.2222*0.3331*-0.3030 0.0393*0.3039*-0.03038*0.033*0.4033*0.30384*0.4048... (5 Replies)
Discussion started by: cdfd123
5 Replies

10. Shell Programming and Scripting

Extarct specific records from wide file

I have a file which is 5 million records. And each records has 412 fields has delimited by "|". So that makes each records to be 2923 bytes long. I wanted to extract specific records like top 100 or 2500 - 5000, 50001 - 10000 etc. from this file. I tried using head command for top 100 records,... (1 Reply)
Discussion started by: acheepi
1 Replies
Login or Register to Ask a Question