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.... :slight_smile:

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


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

This doesn't match your output exactly, but it's how I interpreted your request:

awk -F'[\]:]' '
	BEGIN {n="abcd@xyz.com"}
	FNR==NR && index($0,n) {a[$4]=1}
	FNR!=NR && ($4 in a) {print $0}
' file file

Thanks jethrow,

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

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

That is not an error, just a warning

1 Like