Sed: print the entire line after the match

I got the research results after using sed:

zcat file* | sed -e 's/.*text=\(.*\)status=[^/]*/\1/' | cut -f 1 - | grep "pattern"

But this only shows the part that I cut, how can I print the entire line after the match?

I use zcat, so I can not use awk.

Thanks.

Edited by:

This is my log file:

[01/09/2015 00:00:47]       INFO=54646486432154646 from=steve   idfrom=55516654455457       to=jone       idto=5552045646464 guid=100021623456461451463   n
um=6    text=hi my number is 0 811 22 1/12   status=new      survstatus=new

My goal is to find all users who spam on my site with their phone numbers (using grep "pattern"), and then print the entire line to get all the information about each spam. The problem is that they can be matches in INFO or id, so I use sedto get the text in the first place.

+4
source share
5 answers

, , ? , "", text= status=?

zcat file* | sed -e '/pattern/s/.*text=\(.*\)status=[^/]*/\1/'

, pattern - , .

, \(.*\)status=[^/]* survstatus=new. , , , ? , status=, - , .

" ", , , text=?

sed 's/.*text=//'

. text= . (, , script zcat file* | sed '/pattern/s/.*text=//'... oops, , .)

+2

sed:

$ sed -ne '/pattern/,$ p'
  # alternatively, if you don't want to print the match:
$ sed -e '1,/pattern/ d'

, "text =" "status =" grep, sed cut:

$ grep 'text=.*pattern.* status='
+15

. , n , . n, , , .

cat file | sed -n -e ':start; /pattern/b match;n; b start; :match n; :copy; p; n ; b copy'
+3

awk

awk '/pattern/,EOF'

perhaps it can be combined with all previous operations in awk.

+2
source
zcat file* | sed -e 's/.*text=\(.*\)status=[^/]*/\1/' | ***cut -f 1 - | grep "pattern"***

instead, change the last two segments of your pipeline so that:

zcat file* | sed -e 's/.*text=\(.*\)status=[^/]*/\1/' | **awk '$1 ~ "pattern" {print $0}'**
0
source

Source: https://habr.com/ru/post/1607300/


All Articles