locked
remove text from variable RRS feed

  • Question

  • Hi

    I have a file with the  following  attendance list, I have extract the names who are present(with numeric 1) $_ -like '*: 1*' into a variable $ListA.

    Kevin: 1

    Johnny: 1

    Sean: 

    Chang:

    Mike: 1

    Nelson:

    Which give me 

    Kevin: 1

    Johnny: 1

    Mike: 1

    How do i remove all the : and 1 when output it to txt in one sentence like

    Kevin, Johnny, mike


    Monday, May 15, 2017 8:43 AM

All replies

  • 'Johnny: 1' -replace '\:\s+1'


    \_(ツ)_/

    • Marked as answer by Noobpie Tuesday, May 16, 2017 1:23 AM
    • Unmarked as answer by Noobpie Tuesday, May 16, 2017 1:28 AM
    Monday, May 15, 2017 12:43 PM
  • Thanks jrv, this command doesn't concatenate the 3 line into a single line.
    Tuesday, May 16, 2017 1:38 AM
  • Thanks again,

    i got it.

    $attendancelist = Get-Content c:\$CA.txt | Where-Object {$_ -like '*: 1*'}
    $CA = $Attendance -replace ': 1' , ',' -join " "
    echo $CA | Out-File C:\class501\CA.txt

    • Proposed as answer by Hello_2018 Tuesday, May 16, 2017 8:08 AM
    Tuesday, May 16, 2017 2:48 AM
  • Time to learn PowerShell before it is too late:

    Get-Content c:\$CA.txt | %{$_ -replace '\:\s+1' } | Out-File C:\class501\CAnew.txt


    \_(ツ)_/

    Tuesday, May 16, 2017 3:45 AM