0

I would like to use Zgrep and Awk to print specific lines.

I use the below script. However, I am not able to print the specific line requirement.

zcat SYS.20210519.tgz | awk '/11055/ && /2.5.5.5/'

It would be nice if someone could help. Thanks.

File name : SYS.20210519.tgz

File INPUT :

20210519 072532  11055  ERROR   Connection is not writable, error[grpId[2.5.5.5/49.3.14.13:17126] connId[142706130] testMode[true] connInfo[ConnInfo[connId=142706130, connGrp=2.5.5.5/49.3.14.13:17126,

File output (Needed) :

20210519 072532  11055  ERROR   Connection is not writable, error[grpId[2.5.5.5/49.3.14.13:17126] 
  • 1
    Welcome to SO, thanks for sharing your efforts, please do add your samples of input and expected output more clearly in your question to make it clear. – RavinderSingh13 May 25 '21 at 11:49
  • Thank you for responding. I have edited my question now with the input file and expected output file. Thanks – Vijay Joshua May 25 '21 at 12:02
  • I have edited my Question again. Thanks – Vijay Joshua May 25 '21 at 12:07
  • In what way is your script failing? It **would** print the line you want (plus maybe some others you don't want but idk if that's the problem you're asking about). – Ed Morton May 25 '21 at 14:00

1 Answers1

2

With your shown samples, could you please try following. Using zcat to read your Input_file then sending its output as standard input to awk program. Where using match function to match regex, which will print till value of error[grpId till ] occurrence.

zcat Input_file | 
awk 'match($0,/.*error\[grpId\[[^]]*\]/){print substr($0,RSTART,RLENGTH)}'
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93