Selecting A Block Of Data From A File (AWK)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Selecting A Block Of Data From A File (AWK)
# 1  
Old 02-29-2012
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: Tue Feb 28 17:02:25 12 GMTPID: 10938PPID: 8706User/Grp: 1234/12(user1/grp1)Groups: 12(grp1)Effective privileges: "BASIC"Permitted privileges: "BASIC"Retained privileges: "BASIC"Audit tag: 0: -1:user1:1029472123 TTY: pts/1Return1: 0Arg 1 (file info): given path = "/path/privrun" inode = 333 device = 64, 0x01839 mode = 010588 owner uid/gid = 1500/120 type = regular fileArg 2 (argument list): arg #1 = "cmd1" arg #2 = "cmd2" arg #3 = "cmd3"Other (fie info): inode = -1-----------------------------------------------------------Event: execveTime: Tue Feb 28 17:02:25 12 GMTI need to extract all of the data between the dashed lines.....(there are no spaces between the lilnes)Any help would be extremely appreciated....Many thanks
# 2  
Old 02-29-2012
I would suggest posting the awk code you used, along with the format of the text (that you've already posted) again, and this time using the code tags to keep it readable.
# 3  
Old 02-29-2012
Let me try again, the formatting was terrible (First time on forum - sorry)

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:
Code:
-----------------------------------------------------------
Event: execve
Time: Tue Feb 28 17:02:25 12 GMT
PID: 10938
PPID: 8706
User/Grp: 1234/12(user1/grp1)
Groups: 12(grp1)
Effective privileges: "BASIC"
Permitted privileges: "BASIC"
Retained privileges: "BASIC"
Audit tag: 0: -1:user1:1029472123
TTY: pts/1
Return1: 0
Arg 1 (file info): 
given path = "/path/privrun" 
inode = 333 
device = 64, 0x01839 
mode = 010588 
owner uid/gid = 1500/120 
type = regular file
Arg 2 (argument list): 
arg #1 = "cmd1" 
arg #2 = "cmd2" 
arg #3 = "cmd3"
Other (fie info): 
inode = -1
-----------------------------------------------------------
Event: execve
Time: Tue Feb 28 17:02:25 12 GMT

I need to extract all of the data between the dashed lines based on the search field of ' arg #2 = "cmd2" ' Note: There are no spaces between the lines.

Any help would be extremely appreciated....

Many thanks

Last edited by joeyg; 02-29-2012 at 10:26 AM.. Reason: Wrap programming and data with CodeTags; makes easier to read
# 4  
Old 02-29-2012
Try:
Code:
awk -F'---*' '{print $2}' infile

OK I saw you reposted in a diffent format. Then it won't work

---------- Post updated at 14:57 ---------- Previous update was at 14:52 ----------

Try:
Code:
awk '/---/{p=!p;next}p' infile

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extarct block data using awk

I have 3 block data with Process Beginning and Process Ending I need to Print Begining and ending lines of block data other than sqlExtracts blocks Process Beginning - 2016-04-02-00.36.13---->Print this line Putting Files To daADadD for File will move to /sadafJJHFASJFFASJ/ Extract... (8 Replies)
Discussion started by: sushma123
8 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

awk for selecting columns of different data files

Hello friends, How can I use awk commands to obtain selective blocks from different data files. For example file1 a b c d e f g h i file2 1 2 3 4 5 6 7 8 9 output a b 2 3 d e 5 6 g h 8 9 is it possible ? (2 Replies)
Discussion started by: rpf
2 Replies

4. Shell Programming and Scripting

Help with awk for selecting lines in a file avoiding repetition

Hello, I am using Awk in UBUNTU 12.04. I have a file as following with 48,432,354 lines and 4 fields. The file has this structure (There are repetitions of the first column in several lines) AB_14 S54 A G AB_14 S55 A A AB_14 S56 G G GO_15 S45 T A GO_15 S46 A A PT_16 S33 C C PT_16 ... (4 Replies)
Discussion started by: Homa
4 Replies

5. Shell Programming and Scripting

Selecting data between [ and ]

Hi Team, I am searching through log file using grep -i '<search_key>' <file_name>|awk '{print $18}' example outputs are I would like to select the data between and no other as I am getting some junk characters sometimes which chaging the o/p display format. Kindly assist.... (8 Replies)
Discussion started by: sanjaydubey2006
8 Replies

6. Shell Programming and Scripting

Help with selecting column with awk for a txt file generated by excel

I am new to scripting/programming, so I apologize for any novice questions. I have a tab delimited text file that was saved from excel xls file. I am trying to select only the third column using awk command. My command line is as below: cat test.txt | awk '{print $3}' However, above... (8 Replies)
Discussion started by: SangLad
8 Replies

7. Shell Programming and Scripting

selecting lines using awk

I have a file which contains five hundred thousand lines (500,000). I want to select lines of every 1000 lines from that file using AWK. I can think something like this in bash as below: for lines in {0..500000..1000} do ........ ........ done But I want to use AWK. I do not know how to... (4 Replies)
Discussion started by: vjramana
4 Replies

8. UNIX for Dummies Questions & Answers

Help selecting some rows with awk

Hi there, I have a text file with several colums separated by "|;#" I need to search the file extracting all columns starting with the value of "1" or "2" saving in a separate file just the first 7 columns of each row maching the criteria, with replacement of the saparators in the nearly created... (2 Replies)
Discussion started by: capnino
2 Replies

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

10. 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
Login or Register to Ask a Question