header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

.split()
Last Post 05 Feb 2008 04:31 PM by kctalbot. 4 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
kctalbotUser is Offline
New Member
New Member
Posts:14

--
04 Feb 2008 05:18 PM  

I have a CSV file generated by Sharepoint that contains URLs that I would like to strip out.  split() is breaking on spaces which should give me 7 or 8 lines depending on optional field.  I am trying to save the URLs to use with Invoke.  Some of the URLs, enclosed in parenthesis,  have embedded spaces and also get split which is what I don't want.  I am not seeing a way to leave the URL alone.  What am I missing?



RichSUser is Offline
New Member
New Member
Posts:41

--
04 Feb 2008 06:04 PM  
Split will break on every occurrance of the character you are using to define the split. If you have embedded zeros they will be counted.

Do you just need the URLs? does the CSV have a header row so that you can use something like $_.url to pull out a specific field in each row.

If its a CSV file doesn't it have commas sepaarting the fields? Couldn't they be used for you split?


RichSUser is Offline
New Member
New Member
Posts:41

--
04 Feb 2008 06:06 PM  

Sorry that should have embedded spaces



DonJUser is Offline
PowerShell MVP
Basic Member
Basic Member
Posts:134

--
05 Feb 2008 03:53 PM  
A regex could probably be a better way to do this, especially if your URLs all start with http://. YOu'd just do something like (typing out loud here, so it'll probably not be exact) "http://\w*" as a regex to find everything starting with http:// and match all the way to the next space character. You coudl then look in $matches to get the actual URL that matched.

Of if the URLs all end in a comma then you'll definitely have to tweak it a bit - but a regex (and select-string) is perfect for this. Done with select-string you could actually feed the entire file to it at once and get your URLs in a one-liner.


kctalbotUser is Offline
New Member
New Member
Posts:14

--
05 Feb 2008 04:31 PM  

Don't know whether it is me or the internet connection here, but this is third try at replying since last evening.

I had loaded a previous version of file into Excel and with some macros massaged everything into place.  I had originally thought this looked like samples of hashtables I'd seen, key = value, but realize 700 keys all equal to URL wasn't going to work well.  split looked perfect since it would do what Excel did, preserve the embedded spaces since they were enclosed in quotes.  Since the fields are delimited by spaces, and no commas, it became apparent that Excel is not relying on the .Net framework to handle the import.

regex scares me.  Yes I own the O'Reilly book and even have used regular expressions to black list blocks of IPs, but I know two weeks later I will look at it and try to guess why I did what I did.

What I want to end up with is URLs I can than try loading from another PowerShell script.  I just can't figure out where the example of wait for exit is, and a file I can load into Excel to keep manager happy with all the other information SharePoint generated.  That search took me to web site this morning showing Colin Byrne and Richard made a joint presentation a while ago. 

One more try, I do appreciate the assistance.  I am trying to keep this as simple as possible.  I have been doing this way to long to want to do this all on one line. 

kct


Attachment: 12536075071.txt

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer