in reply to Re: Search and delete
in thread Search and delete

Hi, Thanks, for getting back to me . This are the lines that I wanted to delete . This is what I have tried after opening the File descriptor from my command output . next if $row =~ /^unassigned\n\nOK$/; Below are the lines to be deleted < unassigned physicaldrive 7C:3:7 port 7C:box 3:bay 7 SAS 1 TB OK physicaldrive 7C:3:8 port 7C:box 3:bay 8 SAS 1 TB OK >

Replies are listed 'Best First'.
Re^3: Search and delete
by blindluke (Hermit) on Dec 15, 2014 at 23:51 UTC

    Have you read my response? Please apply some basic formatting to your post, it's completely unreadable right now.

    Can you see four lines in the following output?

    asdfghjklqwertyuiop

    And now?

    asd fghjkl qwertyu iop

    You can always count on people willing to help you in the Monastery. Make it possible for them by not forcing them to guess what your question is.

    - Luke

      Sorry, I am new to this forum . Finding it difficult to understand to post here . Here is my code .
      my %unitMap; my $cmd = "hpacucli ctrl slot=0 pd all show";; open my $fd, "$cmd|" or return \%unitMap; while (my $row = <$fd>) { $row =~ /^$/ and next; $row =~ s/[,|)|(]//g; chomp $row; next if $row =~ /^Smart/g; $row =~ s/^\s+//; next if $row =~ /^unassigned\n\nOK$/; # I am trying to delete the line that starts with unassigned and 2 lin +es after that print "$row\n";
        I am pretty sure you are trying to delete 3 lines, in which you are only reading one line at a time.

        I could handle this by putting in a counter:
        my $counter = 0; if ( $_ =~ /unassigned/ ) { $_ =~ s/.*\n//gi; #delete unassigned line $counter++; #count will be 1 and will be caught by next if stat +ement } if ( $counter = 1 ) { $_ =~ s/.*\n//gi; #delete next line $counter++; #count will be 2 and will be caught by next if stat +ement } if ( $counter = 2 ) { s/.*\n//gi; #delete the 2nd line after unassigned $counter = 0; #make count to 0 until $_ is something you are lo +oking for }
        I dont know how good this will work for your particular problem, but it could give you another way to think about it :)

        EDIT: I did not read the rest of the comments, seems there was a better answer already given.
        Ok, thats code and pattern, but where is the data?
        <code> data data data </code>
Re^3: Search and delete
by Anonymous Monk on Dec 15, 2014 at 23:46 UTC
    Um, thats not code tags :)  <code> code here </code>
Re^3: Search and delete
by pr33 (Scribe) on Dec 15, 2014 at 23:48 UTC
    unassigned -> line 1 to be matched physicaldrive......OK -> line2 physicaldrive ...Ok -> line3