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 - Remove Blank spaces from a Doc

Reply
 
Old 10-17-2008   #1 (permalink)
atorres


 
 

Remove Blank spaces from a Doc

I am trying to format a file that has many blank space in between words, so I
am trying to replace them with a ":"
This is my code, and it is not working:

Get-Content ".\list.log" | ForEach-Object {$_ -replace '\s+(?!$)', ',' } |
Set-Content .\new-list.log"

Any help is appreciated.


My System SpecsSystem Spec
Old 10-18-2008   #2 (permalink)
atorres


 
 

Re: Remove Blank spaces from a Doc

Thanks it did help, in some way, I used (gc list.log) -replace '\s{2,}',':',
but it replaced all blank spaces with ":" so I get:

Server:::::::::::::::System:::::::::
and I am looking for:
Server:System.
I am learning how to write scripts,
Thanks!

"Kiron" wrote:
Quote:

> Try this:
>
> # to replace two or more with a ':'
> (gc list.log) -replace '\s{2,}',':'
>
> # to replace one or more
> (gc list.log) -replace '\s+',':'
>
> --
> Kiron
>
My System SpecsSystem Spec
Old 10-19-2008   #3 (permalink)
atorres


 
 

Re: Remove Blank spaces from a Doc

This is the text that I have:
dapp203ntv MIC CRS Index erver

uproxy01lxv UAT F5 LB reverse proxy

uproxy02lxv UAT F5 LB reverse proxy


And this what I get"

dservera::::::::::::::::::::::::MIC CRS Index erver

pservera::::::::::::::::::::::::UAT F5 LB reverse proxy

qservera::::::::::::::::::::::::UAT F5 LB reverse proxy

Uservera::::::::::::::::::::::::Index server

This is what would like to see

dservera:MIC CRS Index erver
pservera:UAT F5 LB reverse proxy
qservera:UAT F5 LB reverse proxy
Uservera:Index server

"Kiron" wrote:
Quote:

> 'System Server ' -replace '\s{2,}',':'
>
> The multiple ':' in the result you're getting is odd, there should be one
> ':' for any continuous whitespace between words. The ':' after the last
> word -or before the first- can be taken care of with a consecutive
> replacements:
>
> Try this:
>
> ' System Server ' -replace '^\s+|\s+$' -replace '\s+',':'
> ' System Server ' -replace '^\s+|\s+$' -replace '\s{2,}',':'
>
> If multiple ':' are still output, and you _can_ share the first line of
> your list.log, post the output of either:
> "$([int[]][char[]](gc list.log -t 1))"
> # or...
> "$(gc list.log -t (gc list.log -t 1).length -en byte)"
>
> --
> Kiron
>
My System SpecsSystem Spec
Old 10-23-2008   #4 (permalink)
Flowering Weeds


 
 

Re: Remove Blank spaces from a Doc

Quote:

> dapp203ntv MIC CRS Index erver
> uproxy01lxv UAT F5 LB reverse proxy
Mmmm data parsing!

LogParser.exe "SELECT
Field1 AS [The First Field],
Field2 as TheSecondField
FROM aTest123.txt " `
-i tsv -iSeparator spaces `
-headerRow off -nFields 2 `
-o tsv -oSeparator ":" `
-headers off -q on

Returns:

dapp203ntv:MIC CRS Index erver
uproxy01lxv:UAT F5 LB reverse proxy
uproxy02lxv:UAT F5 LB reverse proxy
Uservera:Index server

Just ask any _automation_ tool,
powershell.exe,
user for more information,
about automating
the data parsing tool,
logparser.exe!


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Uninstalled applications left permanent blank spaces in start menu Vista General
How to remove blank space at end of movie project Vista music pictures video
VBScript run generates errors with blank spaces in the string to beexecuted VB Script
blank spaces in display Vista performance & maintenance
remove spaces from end of 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