extract a string after a pattern

后端 未结 4 990
失恋的感觉
失恋的感觉 2021-02-09 11:33

I want to extract the numbers following client_id and id and pair up client_id and id in each line.

For example, for the following lines of log,

User(cli         


        
4条回答
  •  时光取名叫无心
    2021-02-09 12:28

    This might work for you (GNU sed):

    sed -r '/.*(\(client_id:([0-9]+))[^(]*\(id:([0-9]+)/!d;s//\2 \3\n\1/;P;D' file
    
    • /.*(\(client_id:([0-9]+))[^(]*\(id:([0-9]+)/!d if the line doesn't have the intended strings delete it.
    • s//\2 \3\n\1/ re-arrange the line by copying the client_id and moving the first id ahead thus reducing the line for successive iterations.
    • P print upto the introduced newline.
    • D delete upto the introduced newline.

提交回复
热议问题