Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Search for string in CSV and delete line if string found in line

Reply
 
Old 07-02-2007   #1 (permalink)
sherlock


 
 

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 SpecsSystem Spec
Old 07-02-2007   #2 (permalink)
Matt


 
 

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 SpecsSystem Spec
Old 07-02-2007   #3 (permalink)
sherlock


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46