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

Remove data from text file
Last Post 27 Mar 2008 04:54 PM by halr9000. 6 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
jmeddUser is Offline
New Member
New Member
Posts:3
Avatar

--
27 Mar 2008 10:53 AM  

I have a text file containing data in the following format:

username1.xxx.xxx.xxx.companyname

username2.xxx.xxx.xxx.companyname

username3.xxx.xxx.xxx.companyname

basically Novell usernames.

I would like to manipulate the data in the text file so that its transformed to simply

username1

username2

username3

ie. everything after the first dot is removed.

I'm sure there's a real simple way to do this, but I'm darned if I can find it. Whenever I pull the content in using

$a = Get-Content C:\Scripts\UserList.txt

all the commands I try to use to manipulate the text can't be used in an array.

 

bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
27 Mar 2008 01:05 PM  

Try this

$users = Get-Content C:\Scripts\UserList.txt | %{$_.split(".")[ 0 ]}

Edited by halr9000: fixed [ 0 ] string in code sample

Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
jmeddUser is Offline
New Member
New Member
Posts:3
Avatar

--
27 Mar 2008 03:11 PM  

Thanks!

I had everything right in the split except for the [0] .

kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
27 Mar 2008 04:46 PM  
Could you explain the Ύ]? I'm still trying to figure it out.
My blog: http://blogs.powershellcentral.com/kscriss/
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
27 Mar 2008 04:49 PM  
That's a typo generated by the rich text editor we use for the forum. I'll see if I can cut that out.
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
jmeddUser is Offline
New Member
New Member
Posts:3
Avatar

--
27 Mar 2008 04:50 PM  

Its something to do with the formatting on this forum. The code is actually

 

[ 0 ]

 

without the spaces.

halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
27 Mar 2008 04:54 PM  
Funny...the adjective I used to describe aforementioned rich text editor, "< expletive removed >" (literally) was expunged by the editor. :/
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
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