remove all characters in every line starting from the character "\" in a text file using powershell

I have 50 lines text file ($file1) like and i need to remove the characters starting from an specific character "/" until,the end of the line.

Sample text file:

| Area | vserver | file-id |connection-id | session-id | open-mode | path |

| manphsan01 | manphs101 | 9980 | 4278018043 | 5065142205921760710 | rw | Share01\Mandaue\Data01 |

| manphsan01 | manphs101 | 1790 | 4278020659 | 5065142205921763223 | rwd | FinanceDept\ARCHIVING |

| manphsan01 | manphs101 | 1824 | 4278020659 | 5065142205921763223 | rwd | Share01\Cebu\Year2022 |

| manphsan01 | manphs101 | 1976 | 4278020659 | 5065142205921763223 | rwd | SGSDept\General\Document |

My desired output sh0uld be like:

| Area | vserver | file-id |connection-id | session-id | open-mode | path |

| manphsan01 | manphs101 | 9980 | 4278018043 | 5065142205921760710 | rw | Share01 |

| manphsan01 | manphs101 | 1790 | 4278020659 | 5065142205921763223 | rwd | Finance |

| manphsan01 | manphs101 | 1824 | 4278020659 | 5065142205921763223 | rwd | Share01 |

| manphsan01 | manphs101 | 1976 | 4278020659 | 5065142205921763223 | rwd | SGSDept |

the command i used is like this:

$var = Get-content $file1

$var.Substring(0, $var.IndexOf('\')) | FT -AutoSize or 

$var.Substring(0, $var.IndexOf('backslash')) | FT -AutoSize

My command will work if my data is only 1 line but multiple lines it wont work. I am not sure why the 'backslash' is not showing on the command when i posted it.

ny ideas how to make this work?



from Recent Questions - Stack Overflow https://ift.tt/PLaQ9Hl
https://ift.tt/HVwpivm

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)