Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    delete line based on match perl


    Greetings im running a command that captures a lot of lines.

    $ELEMENT = `./my command`;
    print $ELEMENT;

    i need to delete lines that contain a certain string. At this point i think my output is one huge line. i tred saving to an array then iterate over the array a delete the match when it finds it but no luck. help please?
    Thanks

  2. #2
    Quote Originally Posted by bishop2001 View Post
    Greetings im running a command that captures a lot of lines.

    $ELEMENT = `./my command`;
    print $ELEMENT;

    i need to delete lines that contain a certain string. At this point i think my output is one huge line. i tred saving to an array then iterate over the array a delete the match when it finds it but no luck. help please?
    Thanks
    sure we'll help as soon as you show us anything youve actually done. posting two lines from your supposed program isnt a lot. did you bother to try to look at any of the gazillion perl tutorials that tell you how to do a grep? iterate through an array? lots of examples so go find one. if you cant figure out google then you shouldnt be coding

  3. #3
    ok my first step is running the command to capture the output to a scalar.

    @COMMAND_OUTPUT = `./command`;
    this command consists of about 130 lines. Ideally i would like to ignore a subset of lines containing 'x'

    foreach $var (@COMMAND_OUTPUT){
    if ($var =~ m/pattern/) {
    then ignore that string\n;
    }

    i think my initial capture is wrong because i expect 130 elements in that array but there are only 5 when i assign it to a scalar and print. I'm novice here. Thanks,
    $NUM=@COMMAND_OUTPUT;
    print "$NUM\n"; # this says 5 elements

  4. $spacer_open
    $spacer_close
  5. #4
    -->
    Quote Originally Posted by bishop2001 View Post
    ok my first step is running the command to capture the output to a scalar.

    @COMMAND_OUTPUT = `./command`;
    this command consists of about 130 lines. Ideally i would like to ignore a subset of lines containing 'x'

    foreach $var (@COMMAND_OUTPUT){
    if ($var =~ m/pattern/) {
    then ignore that string\n;
    }

    i think my initial capture is wrong because i expect 130 elements in that array but there are only 5 when i assign it to a scalar and print. I'm novice here. Thanks,
    $NUM=@COMMAND_OUTPUT;
    print "$NUM\n"; # this says 5 elements
    so your entire program is five lines long? yea, right. and did you bother to even TRY to look up how to do anything? there is no if...then in perl. and how do you think anyone can tell you why your not getting the right stuff in your array when you dont bother showing us whats going in? what the command is?

    or do you think we can just say 'type this in and your program will work"?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •