简体   繁体   中英

Powershell Trim Space between Sentences

I'm using Powershell to trim spaces between strings, I need help. I'm reading the values into a variable using Get-Content

Here is my input data:

04:31 Alex M.O.R.P.H. & Natalie Gioia - My Heaven http://goo.gl/rMOa2q
[ARMADA MUSIC]

12:37 Chakra - Home (Alexander Popov Remix) http://goo.gl/3janGY
[SOUNDPIERCING]

See the space between the two songs? I want to eliminate these. so that the output is:

04:31 Alex M.O.R.P.H. & Natalie Gioia - My Heaven http://goo.gl/rMOa2q
[ARMADA MUSIC]
12:37 Chakra - Home (Alexander Popov Remix) http://goo.gl/3janGY
[SOUNDPIERCING] 

I put the contents in a file called foo.txt.

foreach ($line in get-content foo.txt) {
   if ($line -ne '') {
      $line
   }
}
$noEmptyLines = Get-Content -Path C:\FilePath\File.Txt | Where-Object{$_ -notmatch "^\s*$"}

您将拥有一个变量,其中将删除仅包含空格的任何行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM