Powershell (Replacing White Spaces with a comma)
The object property values output tends to be tabular with varying white spaces between each column. I’m looking for a script that will allow me to:
Output the object property values to a file
Remove all white spaces encountered (regardless of the number of spaces)
Replace the spaces with one (1) comma
Replace isn’t the answer unless I literally define each instance of spaces and I can’t find any discernable documentation on using Regex…
-- formattting the output doesn't help either...
Any guidance / help would be appreciated
Roderick
Let's say I ran the PowerShell command below:
Get-ClusterResource -Cluster ClusterName | Where-Object {$_.Name -like "SQL Server (*"}
The output would be something along lines of what you see below.
I typically output the result set to a csv file, strip the header, replace the spaces with a single comma, and bulk import the data into a SQL Server table for reporting.
Basically, I'd like a "dynamic way" (not replace with the literal space count between double quotes) of getting rid of the spaces between the columns and replace the spaces with a single comma.
Name State
Group ResourceType
SQL Server (SRV101O) Online SRV101o SQL Server
SQL Server (SRV301O) Online SRV301o SQL Server
SQL Server (SRV201O) Online SRV201o SQL Server
SQL Server (REMSRV101O) Offline REMSRV101o SQL Server
SQL Server (REMSRV301O) Offline REMSRV301o SQL Server
SQL Server (REMSRV201O) Offline REMSRV201o SQL Server
SQL Server (REMSRV401O) Offline REMSRV401O SQL Server
SQL Server (REMSRV501O) Offline REMSRV501O SQL Server
SQL Server (SRV401O) Online SRV401O SQL Server
SQL Server (SRV501O) Online SRV501O SQL Server
Similar Messages
-
Replacing multiple spaces with another character
i need to replace multiple spaces with another char in a string
my code is
Dim text as String="a bit much a little much" Dim arr As String() = text.Split({" "c}, StringSplitOptions.RemoveEmptyEntries)Dim newtext As String = String.Join(" ", arr) MsgBox(newtext)
it returns to "a bit much a little much "
But i want to replace only long spaces with "=" as "a bit much =a little much"
How can i do that?This version uses two spaces to split the string and then trims any additional single spaces. It returns "a bit much = a little much".
Dim text As String = "a bit much a little much "
Dim parts() As String = text.Split({" "}, StringSplitOptions.RemoveEmptyEntries)
Dim newText As String
If parts.Length = 2 Then
newText = parts(0).Trim & " = " & parts(1).Trim
End If -
How to remove white spaces with GUI_Download FM
Hi Gurus,
I need to download my text file using GUI_DOWNLOAD FM without leading white spaces, can u pls advice me.
I am giving the code I am using below.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = l_filename
filetype = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
HEADER = '00'
TRUNC_TRAILING_BLANKS = 'X'
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
SHOW_TRANSFER_STATUS = ABAP_TRUE
IMPORTING
FILELENGTH =
TABLES
data_tab = gt_temp
FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.hi , try this,
REPORT ZMP_SALES_HEDER_DOWLNLOAD.
types:begin of ty_vbak,
vbeln type vbeln,
erdat type erdat,
ernam type ernam,
netwr type netwr_ak,
vkorg type vkorg,
kunnr type kunnr,
end of ty_vbak.
data:it_vbak type table of ty_vbak,
wa_vbak type ty_vbak.
select-options:s_vbeln for wa_vbak-vbeln.
start-of-selection.
select vbeln
erdat
ernam
netwr
vkorg
kunnr from vbak
into table it_vbak
where vbeln in s_vbeln.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
FILENAME = 'C:/temp.XLS'
* FILETYPE = 'ASC'
* APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = IT_VBAK
* FIELDNAMES =
* EXCEPTIONS
* FILE_WRITE_ERROR = 1
* NO_BATCH = 2
* GUI_REFUSE_FILETRANSFER = 3
* INVALID_TYPE = 4
* NO_AUTHORITY = 5
* UNKNOWN_ERROR = 6
* HEADER_NOT_ALLOWED = 7
* SEPARATOR_NOT_ALLOWED = 8
* FILESIZE_NOT_ALLOWED = 9
* HEADER_TOO_LONG = 10
* DP_ERROR_CREATE = 11
* DP_ERROR_SEND = 12
* DP_ERROR_WRITE = 13
* UNKNOWN_DP_ERROR = 14
* ACCESS_DENIED = 15
* DP_OUT_OF_MEMORY = 16
* DISK_FULL = 17
* DP_TIMEOUT = 18
* FILE_NOT_FOUND = 19
* DATAPROVIDER_EXCEPTION = 20
* CONTROL_FLUSH_ERROR = 21
* OTHERS = 22
IF SY-SUBRC = 0.
MESSAGE 'DATA ULOADED TO temp FILE' TYPE 'I'.
ENDIF. -
Replacing multiple spaces with a single space
Hi friends,
I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
Here are the cases:
1. ' a b c d efg h' should be changed to 'a b c d e f g h'
2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
3. 'a b c d e f g h' should not be changed
4. 'abcdefgh' should not be changed
Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
Thanks in advance!Hi,
964559 wrote:
Hi friends,
I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
Here are the cases:
1. ' a b c d efg h' should be changed to 'a b c d e f g h'One solution is to post your string on this site, and then copy it back again. (See below for a more serious solution .)
This site is doing exactly what you want the function to do: it replaces multiple consecutive spaces with a single space. As a result, it's hard to see what you mean.
To preserve spacing on this site, type these 6 characters
\(small letters only, inside curly brackets) before and after each section where you want spacing preserved.
2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
3. 'a b c d e f g h' should not be changed
4. 'abcdefgh' should not be changed
Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
Thanks in advance!Regular expressions make this easy:SELECT TRIM ( REGEXP_REPLACE ( str
, ' +'
) AS compressed_str
FROM table_x;
You can use nested REPLACE calls to get the same results, but it's messy.
Edited by: Frank Kulash on Feb 5, 2013 10:18 AM
Added TRIM -
Replacing Home Space with a specific Group Space.
Hi,
We have a Webcenter Spaces 11.8 environment.
We are trying to completely bypass the home space and take the user to a specific space.
While this is possible to do it through the initial redirection based on application/enterprise role, some re-directions are causing the user to land in the home space.
Also, the user can get to the home space pages by typing in the url. We want to restrict the user from viewing the home space altogether and replace it completely with our group space.
Approach1 : Page Links -
We tried to bring in pages from the group space into the home space navigation model as page links. Even if the group space is public, we cannot link to its pages as we cannot see the pages in the page link popup. Only home space pages are shown. Is this expected? How do we bring in pages from a specific group space into the home page navigation?
Approach 2: Group Space Pages Query -
We can bring all the pages from the "Default Navigation Model" of the group space into the home space navigation model. However, the landing page upon login needs to be a visible page in the home space. How do we get the user redirected to a specific page in a group space and make that node as selected once the user logs in.
Thanks in advance.Hi,
Check this code.
data : role(10) type c value 'crick ter',
role1(10) type c,
role2(10) type c.
write: / role.
SPLIT role AT space INTO role1 role2.
concatenate role1 role2 into role separated by '_'.
write: / role.
<REMOVED BY MODERATOR>
Regards.
Edited by: Alvaro Tejada Galindo on Mar 10, 2008 7:25 PM -
How to replace blank spaces with zero's in the report
hai sdn guys,
we have a requirement where we cannot have any blank fields in the report and i need to replace the blanks with a zero. What is the best way to do it.Hi Sunitha,
It is not proper that you are posting the same question multiple times:
Re: report o/p should not have blank spaces in - in case of no value
should get 0's in place of blank value in the output of the report
That too inspite of my requesting you not to do so.
I am not sure if you have ever gone through the Rules Of Engagement which are prominently posted in each forum, but I think it is SDN courtesy to provide proper feedback when posting a question and assign points as deemed fit. This helps (and motivates) everyone to work on your problem and try to give you a solution. I hope you will be more careful in the future. Thanks! -
Issues in Application table - extra white space with and without scroll bar
1. There is an extra white space that comes after the last column in all the applications table, when there is no scroll lbar.
[http://files.oraclecorp.com/content/Private/Screenshots/Space_ApplicationTable.bmp]
2. If the scroll bar comes up then, there is an extra white space on top of the scroll bar.
[http://www-apps.us.oracle.com/~jkodiyan/fusion/screenshots/appstablespace1.jpg]It would be best to follow this up in your internal ApplCore / ADF frontend forum..
screenshot for issue #1: http://www-apps.us.oracle.com/~jkodiyan/fusion/screenshots/appstablespace2.jpg
That's an internal Oracle URL - Probably not a good idea to share on the internet and it's not accessible outside anyway... -
How to hide white space with pen tool
Ok so im tracing with the pen tool, and there is a white area that fills in unnecessarily. The lynda video says use View>Outline, but that is making the thing i am tracing disappear! how do i make it so the white polygons only disappear on the layer with the pen?
Set the Pen tool to have a stroke and no fill. Either will do it.
-
Replacing many spaces with single space in a string
Hi!
I have the following strings:
"Eric B"
"John A"
"Mary Anne C"But I want them to be like this:
"Eric B"
"John A"
"Mary Anne C"Do anyone have an idea how to do this?
Edited by: suladna on Aug 2, 2008 5:42 AMUse this:
String s = "Mary Anne C";
System.out.println(s.replaceAll("\\s+", " "));Edited by: prigas on Aug 2, 2008 6:15 AM -
CLOB to BLOB replacing spaces with Â
I have a CLOB that we are converting to a BLOB using DBMS_LOB.CONVERTTOBLOB and then serving it up as a file using WPG_DOCLOAD.DOWNLOAD_FILE. When you open the file, it is replacing the spaces with a Â.
Any thoughts?Most likely, the spaces in the original CLOB were not regular spaces (0x20) but rather non-breaking spaces (0xA0).
What's the target encoding used to convert to BLOB? I suppose UTF-8?
UTF-8 encodes non-breaking spaces as 0xC2A0, where 0xC2 is specifically the codepoint for "Â". So I think the tool you're using doesn't support UTF-8, or doesn't recognize the file as being properly encoded.
Edited by: odie_63 on 14 août 2012 14:26 -
HELP : Replacing Space with any character !
Hi !
How do I replace any spaces in a strings passed from a FORM INPUT, with a different character.
I tried doing this
String s= request.getParameters("info");
s.replace(' ','_');
But it keep giving me error.
it there any simpler way of doign this?
Thank you
KHi !
I am new to JSP,
It keep giving a null pointer exception when i use it with JSP
So i did this it work fine on the try section
and once it is in the catch section it keeps giving me Nullpointer exceptions again.
IS there any other way replacing the space with a "-" or anything..?
Thanks for your help.
here is the code
String r_space ="";
try {
r_space=value.replace(' ','+');
out.println("r_space : try " r_space "<br>");
catch(NullPointerException e) {
System.out.println("Recaught: " + e );
r_space=value.replace(' ','+');
out.println("r_space : cathc" r_space "<br>"); -
When generating layers it replaces spaces with underscores
Hi All,
I am working now with RH8, and when I am saving projects and give the name, let's say "my file.chm" it replaces the space with an underscore and the name becomes "my_file.chm". Is it possible to do anything about that?
Thank youI think that what I said means you cannot generate with spaces.
Bug? It has done it that way for several versions and I believe it is important if you are creating merged CHM help.
Submit a bug request or feature change request according to your point of view.
Please follow this link.
http://www.Adobe.com/cfusion/mmform/index.cfm?name=wishform&product=38
See www.grainge.org for RoboHelp and Authoring tips
@petergrainge -
Replace period with white space
I am trying to replace a period in a string with a white space. It does not want to work with a period but works just fine with a comma!
Please can somebody tell me what I am doing wrong.
This is the code that I am using:
System.out.println("Unicode:" + "\u002E");
CharSequence inputStr = "12.345,67";
String patternStr = "\u002E";
String replacementStr = " ";
//Compile regular expression
Pattern pattern = Pattern.compile(patternStr);
//Replace all occurrences of pattern in input
Matcher matcher = pattern.matcher(inputStr);
String output = matcher.replaceAll(replacementStr);
System.out.println("output:" + output);As mentioned "." is considered differently in regular expressions. You can change the patterStr to "[.]" and your code will work.
Since you have used replaceAll() I guess as the size of inputStr varies many thousand seperator can occur. Even then the fix mentioned by me will work
Thanks
Arun -
Replacing Selected Areas with White Space
I am using Acrobat version 8 on an XP Pro SP2 system.
I have a PDF file. Certain selected areas I wish to replace with pure white space. How can I do that?You will find other ways which SEEM to remove blank material but avoid
them like the plague since it is very easy to get back the hidden
material. Redaction needs specialist tools. There is a plug-in, Redax
from http://www.appligent.com/
Aandi Inston -
Replacing character and number e.g #1154;#" with a comma using powershell
Hi there,
How can i replace
I have a string like below and would like to replace ";#1154;#" with a comma.
tried using (;#)\d{4}(;#)" but it doesnt work
Amber Wood;#1154;#John Roberts;#1121;#Peter Ma;#1597;#
Thanks in Advance
Output should be :
Amber Wood,John Roberts,Peter MaThe regex is almost right, but you don't need the normal brackets. If you remove them as per :
$a = "Amber Wood;#1154;#John Roberts;#1121;#Peter Ma;#1597;#"
$b = $a -replace ";#\d{4};#",","
$b
you'll see that works.
Maybe you are looking for
-
I have my photos stored on an external hard drive (Maxtor). The external hard drive has been split into two partitions, with the photos in one and the rest in another. This was because my (very) old Mac did not have space in its internal hard drive a
-
Abap based on object oriented program
hi all, I am knew in OOPS as i want to make a autority object that is globally used in several reports in our several company can u provide me such kind of authority object which uses check on user name sales organization sales division sales group t
-
Okay, am I the only one that would like to NOT have to go into the Preferences>Advanced>Importing menu just to change the ripping/converting format??? How hard would it be to show the last 3-5 settings in the Advanced menu? For those of us that use i
-
Having a qt movie auto play and loop without controls
I have a qt movie that I want to place on a page in iweb - but i want it to autoplay and loop and do not want the controls to show at the bottom of the movie- can this be done? thanks
-
After creating an iDVD movie containing multiple video clips and slideshows, one of the video clips Loops (but only once) before proceeding to the following slide show. I don't want it to loop but don't know how to stop it. Because it only loops once