![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Search for string in CSV and delete line if string found in line Hi, don't really know where to start with this one! I've run a report finding all PST files on our network, however, i have a lot of duplicates where the report has pulled multiple paths for each PST file... this is due to admin share paths as well as normal share filepaths. For example: \\servername\f$\username\pstfilename \\servername\sharename\pstfilename \\servername\username$\pstfilename i just need to keep the file path containing username$, therefore can anyone suggest a way to loop through the CSV file searching for 'sharename' or admin share (i.e. f$) and remove the line that contains it? By default the username$ lines will not be removed as i'll never be searching for those strings. Any and all help appreciated, thanks sherlock |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Search for string in CSV and delete line if string found in line You can use where-object with the * wildcards. PS > cat report.txt \\servername\f$\username\pstfilename \\servername\sharename\pstfilename \\servername\username$\pstfilename PS > cat report.txt | where { $_ -notlike "*f$*" -and $_ -notlike "*sharename*" } \\servername\username$\pstfilename Hope this helps, Matt sherlock wrote: > Hi, don't really know where to start with this one! I've run a report > finding all PST files on our network, however, i have a lot of > duplicates where the report has pulled multiple paths for each PST > file... this is due to admin share paths as well as normal share > filepaths. > > For example: > \\servername\f$\username\pstfilename > \\servername\sharename\pstfilename > \\servername\username$\pstfilename > > i just need to keep the file path containing username$, therefore can > anyone suggest a way to loop through the CSV file searching for > 'sharename' or admin share (i.e. f$) and remove the line that contains > it? By default the username$ lines will not be removed as i'll never > be searching for those strings. > > Any and all help appreciated, thanks > > sherlock |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Search for string in CSV and delete line if string found in line Matt, that's great... it does exactly what i wanted and i can remove all the unwanted material in one pass; wouldn't have thought of doing it like this (and not an IF statement is sight!) ![]() Thanks loads! sherlock |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Need full line of text from select-string | PowerShell | |||
| Chomp Echo String; No New Line Please! | VB Script | |||
| Write every line except the one with first occurence of a string | PowerShell | |||
| Encountered end of line while processing a string token | PowerShell | |||
| Getting the next line after a string | PowerShell | |||