Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

339 views
Skip to first unread message

sherlock

unread,
Jul 2, 2007, 1:12:42 PM7/2/07
to
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

Matt

unread,
Jul 2, 2007, 3:21:52 PM7/2/07
to
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

unread,
Jul 2, 2007, 4:42:54 PM7/2/07
to
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


0 new messages