in reply to Join lines that match an string

Please read How do I post a question effectively?. What have you tried? What didn't work? Why do you want/need a one-liner? What does sample input look like? What does expected output look like? Demonstrated effort is appreciated around here.

perl -e 'while(<>){chomp; last if /p_agrs/;print if /remotely/}' < input.txt

might do what you intend. But it might not. If it doesn't meet spec, please post again with greater specificity.

Replies are listed 'Best First'.
Re^2: Join lines that match an string
by ranrodrig (Novice) on Jul 12, 2010 at 22:08 UTC

    Sorry for not posting an example, but here it is, so what I need to do is join in one line all the lines that match "remotely" on it (include it) and stop where it's an "p_agrs" match, does this make sense?

    EV = 0x10eb250 (class, event_handle: 3503519, mc_ueid: 1278629168) 20100708 224608.259843 RULES: IMC110203I: #3503519: $EV.m c_host 20100708 224608.260757 RULES: IMC110801I: #3503519: Rule e execution starting with . . . msg='script to be execute remotely: exists("TRUSTEDALARM"); Local Id: Rem_010965WAP_18504'; . . . p_agrs
      "...does this make sense?"

      Better, but without more sample data (including examples of non-desired matches) requested above, not enough.

      You have given an input, but no output. Without that, how can we know if our code outputs to spec? If you run my code above against your input file, do you get what you expect?

        Kennethk, there's no output after running your code

        Now let me clarify myself; I have a file with tons of lines, but there're many lines that I want to join in one and I found that I can match the start with "remotely" and the end with "p_agrs", so the lines that are in the middle would be in the one which contains "remotely", later I'll drop the rest of them using a grep remotely data01 > data02