in reply to Join multiple lines in a string based on regex.

Try (Updated:simplified code):

#! perl -sw use strict; while( <DATA> ) { chomp; print "$_ "; unless( $. % 3 ) { print "\n"; } } __DATA__ array A physicaldrive 2C:1:1 port 2C:box 1:bay 1 SAS 1 TB OK physicaldrive 2C:1:2 port 2C:box 1:bay 2 SAS 1 TB OK array B physicaldrive 2C:1:3 port 2C:box 1:bay 3 SAS 1 TB OK physicaldrive 2C:1:4 port 2C:box 1:bay 4 SAS 1 TB OK array C physicaldrive 3C:1:5 port 3C:box 1:bay 5 SAS 1 TB OK physicaldrive 3C:1:6 port 3C:box 1:bay 6 SAS 1 TB OK array D physicaldrive 3C:1:7 port 3C:box 1:bay 7 SAS 1 TB OK physicaldrive 3C:1:8 port 3C:box 1:bay 8 SAS 1 TB OK

Ouput:

C:\test>junk array A physicaldrive 2C:1:1 port 2C:box 1:bay 1 SAS 1 TB OK physical +drive 2C:1:2 port 2C:box 1:bay 2 SAS 1 TB OK array B physicaldrive 2C:1:3 port 2C:box 1:bay 3 SAS 1 TB OK physical +drive 2C:1:4 port 2C:box 1:bay 4 SAS 1 TB OK array C physicaldrive 3C:1:5 port 3C:box 1:bay 5 SAS 1 TB OK physical +drive 3C:1:6 port 3C:box 1:bay 6 SAS 1 TB OK

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Join multiple lines in a string based on regex. (Updated)
by pr33 (Scribe) on Dec 16, 2014 at 20:15 UTC
    Thanks for the reply . It seems we are combining every 3 lines in to a single line , If I am not wrong . The O/P could even stretch to more than 3 lines after matching array and until it hits the next array string .
      The O/P could even stretch to more than 3 lines after matching array and until it hits the next array string

      Then it is a good idea to present sample data that shows that.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.