Grep username and get all the lines with thread numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep username and get all the lines with thread numbers
# 1  
Old 03-01-2014
Grep username and get all the lines with thread numbers

I need help to extract the file. If I am entering the user name like abcd@xyz.com, search the username and get the tread number. Once will get thread number all the line having same threadnumber wanted to keep in seperate file. It can be more than thread number for single username.


For example abcd@xyz.com user has thread number 4 and 2 given in red color(it may be more than one thread numbers with same user).So all the lines which matches the username and coressponding thread number wanted to keep in separate file. Sample input and outputfile has given below


Need advise.... Smilie

Code:
Input file :

......
......
  20140228 03:10:47.159 contain [WebContainer : 4] - statement1
  20140228 03:10:47.159 Design [Web : 4] - statement2
  20140228 03:10:47.160 DEtest [ntainer : 4] - statement3
  20140228 03:10:47.160 DEasdf [Wainer : 4] - statement4
  20140228 03:10:47.160 BUG [Wainer : 4] - decoded xbaks Cookie: abcd@xyz.com|sdct2181||ss553h other thinkgs

  20140228 03:10:47.160 reBUG [WebCont : 4] - statement5
  20140228 03:10:47.160 true1 [tainer : 3] - statement26
  20140228 03:10:47.160 true1 [tainer : 7] - statement27
  ....
  ....
  20140228 03:10:47.160 DEresult [Weainer : 4] - statement22
  20140228 03:10:47.160 DEresult [Weainer : 5] - statement23
  20140228 03:10:47.160 fail [asdfg : 5] - statement24
  20140228 03:10:47.160 true1 [tainer : 5] - statement25
  20140228 03:10:47.160 true1 [tainer : 5] - statement25
  20140228 03:10:47.160 true1 [tainer : 5] - statement25 testing efgh@xyz.com hello testing
  20140228 03:10:47.160 true1 [tainer : 5] - statement25
  20140228 03:10:47.166 DEasd [ainer : 4] - statement26
  20140228 03:10:47.166 DErub [WebCon : 4] - statement27
  20140228 03:10:47.166 DEtest [WebCont : 4] - statement28
  .....
  .....
   
  20140228 03:10:47.166 Data [asdfg : 4] - statement45
  20140228 03:10:47.166 Bug [WebCo : 4] - statement46
  20140228 03:10:47.166 DEBUG [information : 4] - statement47
  20140228 03:10:57.603 asdfds [WebContainer : 2] - statement48
  20140228 03:10:57.603 DEBUG [WebConta : 2] - statement49
  20140228 03:10:57.603 BUGdetect [WebContai : 2] - statement50
  20140228 03:10:57.603 asdfds [WebContainer : 6] - statement555
  20140228 03:10:47.160 true1 [tainer : 5] - statement50
  20140228 03:10:57.603 Defgh [Web : 2] - statement51
  20140228 03:10:57.604 hijkl [qwert : 2] - statement52
  20140228 03:10:57.604 mnopq [asdfg : 2] - statement53
  20140228 03:10:57.604 rstuv [WebC : 2] - statement54 : als kasfn kasf Cookie: abcd@xyz.com|||ctasdf2181
  20140228 03:10:57.604 wxyz [WebCo : 2] - statement55
  20140228 03:10:57.604 Dtest [WebCo : 2] - statement56
  20140228 03:10:57.604 Dresult [WebCon : 2] - statement57
  20140228 03:10:47.160 true1 [tainer : 2] - statement58
  .......
  ......
  20140228 03:10:57.604 redebug [zxcvb : 2] - statement71
  20140228 03:10:57.604 Data [poiuy : 2] - statement59
  .........

20140228 03:10:57.604 Datachange [poiuy : 4] - statement90 
20140228 03:10:57.604 Data [poiuy : 4] - statement91

Code:
Output file :

  20140228 03:10:47.159 contain [WebContainer : 4] - statement1
  20140228 03:10:47.159 Design [Web : 4] - statement2
  20140228 03:10:47.160 DEtest [ntainer : 4] - statement3
  20140228 03:10:47.160 DEasdf [Wainer : 4] - statement4
  20140228 03:10:47.160 BUG [Wainer : 4] - decoded xbaks Cookie: abcd@xyz.com|sdct2181||ss553h other thinkgs

  20140228 03:10:47.160 reBUG [WebCont : 4] - statement5
  
  20140228 03:10:47.160 DEresult [Weainer : 4] - statement22  
  20140228 03:10:47.166 DEasd [ainer : 4] - statement26  20140228 03:10:47.166 DErub [WebCon : 4] - statement27
  20140228 03:10:47.166 DEtest [WebCont : 4] - statement28
       
  20140228 03:10:47.166 Data [asdfg : 4] - statement45
  20140228 03:10:47.166 Bug [WebCo : 4] - statement46
  20140228 03:10:47.166 DEBUG [information : 4] - statement47
  20140228 03:10:57.603 asdfds [WebContainer : 2] - statement48
  20140228 03:10:57.603 DEBUG [WebConta : 2] - statement49
  20140228 03:10:57.603 BUGdetect [WebContai : 2] - statement50
  20140228 03:10:57.603 Defgh [Web : 2] - statement51
  20140228 03:10:57.604 hijkl [qwert : 2] - statement52
  20140228 03:10:57.604 mnopq [asdfg : 2] - statement53
  20140228 03:10:57.604 rstuv [WebC : 2] - statement54 : als kasfn kasf Cookie: abcd@xyz.com|||ctasdf2181
  20140228 03:10:57.604 wxyz [WebCo : 2] - statement55
  20140228 03:10:57.604 Dtest [WebCo : 2] - statement56
  20140228 03:10:57.604 Dresult [WebCon : 2] - statement57
  
  
  20140228 03:10:57.604 redebug [zxcvb : 2] - statement58
  20140228 03:10:57.604 Data [poiuy : 2] - statement59

20140228 03:10:57.604 Datachange [poiuy : 4] - statement90 
20140228 03:10:57.604 Data [poiuy : 4] - statement91


Last edited by nes; 03-01-2014 at 03:54 AM..
# 2  
Old 03-01-2014
This doesn't match your output exactly, but it's how I interpreted your request:
Code:
awk -F'[\]:]' '
	BEGIN {n="abcd@xyz.com"}
	FNR==NR && index($0,n) {a[$4]=1}
	FNR!=NR && ($4 in a) {print $0}
' file file

# 3  
Old 03-04-2014
Thanks jethrow,

Could you please explain the code, as I am getting following error

Code:
awk: warning: escape sequence `\]' treated as plain `]'

# 4  
Old 03-04-2014
That is not an error, just a warning
This User Gave Thanks to SriniShoo For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

OpenMP and MPI hybrid thread numbers

hi, I have two basic questions, I will be really grateful if I receive any comment from you, I have an MPI code where I am trying to implement OpenMP directives. The machine where I run the code has 16 cores. I run the code with export OMP_NUM_THREADS=2 mpirun -np 4 ./exec If I... (0 Replies)
Discussion started by: armando_2011
0 Replies

2. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

3. Shell Programming and Scripting

dynamic thread in grep

hi name$count = some dynamic value now i want to use dat dynamic value in grep so how m i supposed to do dat i tried `grep $(name$count) source` , it is not working ...... what will be after grep so dat i will be... (4 Replies)
Discussion started by: Gl@)!aTor
4 Replies

4. UNIX for Dummies Questions & Answers

grep quoted numbers from lines

I want to parse the lines and want to extract the double quoted numbers as: "SQL3149N "72" rows were processed from the input file. "0" rows were successfully inserted into the table. "0" rows were rejected." and want the output in 3 variables like a=72 b=0 c=0 thanks in advance ... (3 Replies)
Discussion started by: mahesh_191
3 Replies

5. Shell Programming and Scripting

Extract Log lines with Thread-(regex)

Hi everyone, Fist of all I must confess that I am pretty new in the Unix environment and especially to shell scripting, however due to work related requirements I have started to analyze software specific logs. The logs are structured so that it records by sessionID AND/OR Thread number, the... (3 Replies)
Discussion started by: sushimatt
3 Replies

6. UNIX and Linux Applications

grep file to find unique instances of username

hello - A SystemOut.log file has recurring entries that follow this format: Principal: auth9.nick.al.gov:389/USERNAME Over the course of a day thousands of lines similar to this are produced, with each username represented hundreds of times. I need to create a new file that shows... (4 Replies)
Discussion started by: 1075FJ40
4 Replies

7. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

8. UNIX Desktop Questions & Answers

grep numbers

Hi all, I am new to unix and struggling to do the below I have few lines in a xml <title>abc:1</title> <description>abc:2</description> <language>abc:3</language> Is it possible to extract only the entire word like abc:1 abc:2 abc:3 instead of the entire line into a new file . Kindly... (3 Replies)
Discussion started by: umapearl
3 Replies

9. UNIX for Dummies Questions & Answers

grep numbers

Hello, I'm trying to grep for digits surrounded by non digits and I'm obviously misinformed. Could someone help me get this sorted out here is what I have that is not working grep -ho '\D(\{11\})\D' *.txt (5 Replies)
Discussion started by: mcgrailm
5 Replies

10. Shell Programming and Scripting

grep for non numbers

Hi, I want to find out whether a string contains non numbers and + and - example : Str="0005000A" - It contains A Str="0005000+" - No problem What I have done is , echo $Str | grep I will have to list out all non numeric characters... (6 Replies)
Discussion started by: shihabvk
6 Replies
Login or Register to Ask a Question