delete a matched string in a condition, PowerShell












0















the idea is to import a csv, and then if the value "infohostname" contains a nullorwithespace delete the entire line



    Function Last_NAS_Parse {

$Import_IP = Import-Csv -Path "$destination_RAW_NASaudit_nas_8_$((Get-Date).ToString('yyyy-MM-dd')).txt" -Header @("date","infohostname","Version","SMTP","Value_1","Value_2","Value_3","Value_4","Value_5","Value_6","Value_7","Value_8","Value_9")
$Import_IP | ForEach-Object {
if ( [string]::IsNullOrWhiteSpace($_.infohostname)


}


But don't know how can i delete the line after this is selected, thanks.










share|improve this question























  • Firstly, your code is missing parentheses and brackets in order to compile as posted. Is your goal to delete the entire row from the file, or simply clear it?

    – trebleCode
    Nov 23 '18 at 19:10











  • @trebleCode the idea is just to delete the entire row from the file

    – A.lacorazza
    Nov 23 '18 at 19:12
















0















the idea is to import a csv, and then if the value "infohostname" contains a nullorwithespace delete the entire line



    Function Last_NAS_Parse {

$Import_IP = Import-Csv -Path "$destination_RAW_NASaudit_nas_8_$((Get-Date).ToString('yyyy-MM-dd')).txt" -Header @("date","infohostname","Version","SMTP","Value_1","Value_2","Value_3","Value_4","Value_5","Value_6","Value_7","Value_8","Value_9")
$Import_IP | ForEach-Object {
if ( [string]::IsNullOrWhiteSpace($_.infohostname)


}


But don't know how can i delete the line after this is selected, thanks.










share|improve this question























  • Firstly, your code is missing parentheses and brackets in order to compile as posted. Is your goal to delete the entire row from the file, or simply clear it?

    – trebleCode
    Nov 23 '18 at 19:10











  • @trebleCode the idea is just to delete the entire row from the file

    – A.lacorazza
    Nov 23 '18 at 19:12














0












0








0


1






the idea is to import a csv, and then if the value "infohostname" contains a nullorwithespace delete the entire line



    Function Last_NAS_Parse {

$Import_IP = Import-Csv -Path "$destination_RAW_NASaudit_nas_8_$((Get-Date).ToString('yyyy-MM-dd')).txt" -Header @("date","infohostname","Version","SMTP","Value_1","Value_2","Value_3","Value_4","Value_5","Value_6","Value_7","Value_8","Value_9")
$Import_IP | ForEach-Object {
if ( [string]::IsNullOrWhiteSpace($_.infohostname)


}


But don't know how can i delete the line after this is selected, thanks.










share|improve this question














the idea is to import a csv, and then if the value "infohostname" contains a nullorwithespace delete the entire line



    Function Last_NAS_Parse {

$Import_IP = Import-Csv -Path "$destination_RAW_NASaudit_nas_8_$((Get-Date).ToString('yyyy-MM-dd')).txt" -Header @("date","infohostname","Version","SMTP","Value_1","Value_2","Value_3","Value_4","Value_5","Value_6","Value_7","Value_8","Value_9")
$Import_IP | ForEach-Object {
if ( [string]::IsNullOrWhiteSpace($_.infohostname)


}


But don't know how can i delete the line after this is selected, thanks.







powershell csv parsing text-parsing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 19:02









A.lacorazzaA.lacorazza

426




426













  • Firstly, your code is missing parentheses and brackets in order to compile as posted. Is your goal to delete the entire row from the file, or simply clear it?

    – trebleCode
    Nov 23 '18 at 19:10











  • @trebleCode the idea is just to delete the entire row from the file

    – A.lacorazza
    Nov 23 '18 at 19:12



















  • Firstly, your code is missing parentheses and brackets in order to compile as posted. Is your goal to delete the entire row from the file, or simply clear it?

    – trebleCode
    Nov 23 '18 at 19:10











  • @trebleCode the idea is just to delete the entire row from the file

    – A.lacorazza
    Nov 23 '18 at 19:12

















Firstly, your code is missing parentheses and brackets in order to compile as posted. Is your goal to delete the entire row from the file, or simply clear it?

– trebleCode
Nov 23 '18 at 19:10





Firstly, your code is missing parentheses and brackets in order to compile as posted. Is your goal to delete the entire row from the file, or simply clear it?

– trebleCode
Nov 23 '18 at 19:10













@trebleCode the idea is just to delete the entire row from the file

– A.lacorazza
Nov 23 '18 at 19:12





@trebleCode the idea is just to delete the entire row from the file

– A.lacorazza
Nov 23 '18 at 19:12












2 Answers
2






active

oldest

votes


















1














IMO you don't need a function just a Where-Object:



$Header = ("date","infohostname","Version","SMTP","Value_1","Value_2","Value_3","Value_4","Value_5","Value_6","Value_7","Value_8","Value_9")
$Import_IP = Import-Csv -Path "$destination_RAW_NASaudit_nas_8_$((Get-Date).ToString('yyyy-MM-dd')).txt" -Header $Header |
Where-Object {![string]::IsNullOrWhiteSpace($_.infohostname)}


But of course you could wrap that in a function

(but a function without passed parameters and returned values isn't a real function)






share|improve this answer































    0














    Loop over the results and store only objects where that boolean evaluation is true, and create a new file. In order to delete the row of the existing file, I believe you'd have to convert it to XLS/X and access it as a COM object



    $results = @()
    Function Last_NAS_Parse {

    $Import_IP = Import-Csv -Path C:pathtofile.csv
    $Import_IP | ForEach-Object {
    if ( [string]::IsNullOrWhiteSpace($_.infohostname))
    {
    Out-Null
    }
    else
    {
    $results += $_
    }
    }
    }

    Last_NAS_Parse
    $results | Export-CSV "C:exportpathofnewfile.csv"





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451813%2fdelete-a-matched-string-in-a-condition-powershell%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      IMO you don't need a function just a Where-Object:



      $Header = ("date","infohostname","Version","SMTP","Value_1","Value_2","Value_3","Value_4","Value_5","Value_6","Value_7","Value_8","Value_9")
      $Import_IP = Import-Csv -Path "$destination_RAW_NASaudit_nas_8_$((Get-Date).ToString('yyyy-MM-dd')).txt" -Header $Header |
      Where-Object {![string]::IsNullOrWhiteSpace($_.infohostname)}


      But of course you could wrap that in a function

      (but a function without passed parameters and returned values isn't a real function)






      share|improve this answer




























        1














        IMO you don't need a function just a Where-Object:



        $Header = ("date","infohostname","Version","SMTP","Value_1","Value_2","Value_3","Value_4","Value_5","Value_6","Value_7","Value_8","Value_9")
        $Import_IP = Import-Csv -Path "$destination_RAW_NASaudit_nas_8_$((Get-Date).ToString('yyyy-MM-dd')).txt" -Header $Header |
        Where-Object {![string]::IsNullOrWhiteSpace($_.infohostname)}


        But of course you could wrap that in a function

        (but a function without passed parameters and returned values isn't a real function)






        share|improve this answer


























          1












          1








          1







          IMO you don't need a function just a Where-Object:



          $Header = ("date","infohostname","Version","SMTP","Value_1","Value_2","Value_3","Value_4","Value_5","Value_6","Value_7","Value_8","Value_9")
          $Import_IP = Import-Csv -Path "$destination_RAW_NASaudit_nas_8_$((Get-Date).ToString('yyyy-MM-dd')).txt" -Header $Header |
          Where-Object {![string]::IsNullOrWhiteSpace($_.infohostname)}


          But of course you could wrap that in a function

          (but a function without passed parameters and returned values isn't a real function)






          share|improve this answer













          IMO you don't need a function just a Where-Object:



          $Header = ("date","infohostname","Version","SMTP","Value_1","Value_2","Value_3","Value_4","Value_5","Value_6","Value_7","Value_8","Value_9")
          $Import_IP = Import-Csv -Path "$destination_RAW_NASaudit_nas_8_$((Get-Date).ToString('yyyy-MM-dd')).txt" -Header $Header |
          Where-Object {![string]::IsNullOrWhiteSpace($_.infohostname)}


          But of course you could wrap that in a function

          (but a function without passed parameters and returned values isn't a real function)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 19:26









          LotPingsLotPings

          19.2k61532




          19.2k61532

























              0














              Loop over the results and store only objects where that boolean evaluation is true, and create a new file. In order to delete the row of the existing file, I believe you'd have to convert it to XLS/X and access it as a COM object



              $results = @()
              Function Last_NAS_Parse {

              $Import_IP = Import-Csv -Path C:pathtofile.csv
              $Import_IP | ForEach-Object {
              if ( [string]::IsNullOrWhiteSpace($_.infohostname))
              {
              Out-Null
              }
              else
              {
              $results += $_
              }
              }
              }

              Last_NAS_Parse
              $results | Export-CSV "C:exportpathofnewfile.csv"





              share|improve this answer




























                0














                Loop over the results and store only objects where that boolean evaluation is true, and create a new file. In order to delete the row of the existing file, I believe you'd have to convert it to XLS/X and access it as a COM object



                $results = @()
                Function Last_NAS_Parse {

                $Import_IP = Import-Csv -Path C:pathtofile.csv
                $Import_IP | ForEach-Object {
                if ( [string]::IsNullOrWhiteSpace($_.infohostname))
                {
                Out-Null
                }
                else
                {
                $results += $_
                }
                }
                }

                Last_NAS_Parse
                $results | Export-CSV "C:exportpathofnewfile.csv"





                share|improve this answer


























                  0












                  0








                  0







                  Loop over the results and store only objects where that boolean evaluation is true, and create a new file. In order to delete the row of the existing file, I believe you'd have to convert it to XLS/X and access it as a COM object



                  $results = @()
                  Function Last_NAS_Parse {

                  $Import_IP = Import-Csv -Path C:pathtofile.csv
                  $Import_IP | ForEach-Object {
                  if ( [string]::IsNullOrWhiteSpace($_.infohostname))
                  {
                  Out-Null
                  }
                  else
                  {
                  $results += $_
                  }
                  }
                  }

                  Last_NAS_Parse
                  $results | Export-CSV "C:exportpathofnewfile.csv"





                  share|improve this answer













                  Loop over the results and store only objects where that boolean evaluation is true, and create a new file. In order to delete the row of the existing file, I believe you'd have to convert it to XLS/X and access it as a COM object



                  $results = @()
                  Function Last_NAS_Parse {

                  $Import_IP = Import-Csv -Path C:pathtofile.csv
                  $Import_IP | ForEach-Object {
                  if ( [string]::IsNullOrWhiteSpace($_.infohostname))
                  {
                  Out-Null
                  }
                  else
                  {
                  $results += $_
                  }
                  }
                  }

                  Last_NAS_Parse
                  $results | Export-CSV "C:exportpathofnewfile.csv"






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 19:18









                  trebleCodetrebleCode

                  762616




                  762616






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451813%2fdelete-a-matched-string-in-a-condition-powershell%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      To store a contact into the json file from server.js file using a class in NodeJS

                      Marschland

                      Redirect URL with Chrome Remote Debugging Android Devices