{"id":86277,"date":"2019-08-28T15:00:28","date_gmt":"2019-08-28T23:00:28","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/scripting\/?p=86277"},"modified":"2019-08-29T11:11:05","modified_gmt":"2019-08-29T19:11:05","slug":"powertip-using-powershell-to-convert-raw-text-to-a-comma-separated-columm","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-using-powershell-to-convert-raw-text-to-a-comma-separated-columm\/","title":{"rendered":"PowerTip: Using PowerShell to Convert raw Text to a Comma Separated columm"},"content":{"rendered":"<p><strong>Summary<\/strong>: Using PowerShell and a very simple Regular Expression to convert Random counts of spaces to a Comma<\/p>\n<p><img decoding=\"async\" width=\"34\" height=\"34\" class=\"wp-image-86278\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/08\/a-picture-containing-scissors-description-automat-2.jpeg\" alt=\"A picture containing scissors Description automatically generated\" \/><\/p>\n<p>Hey Doctor Scripto! I have some string based output from a non PowerShell application. The output is good but I need to easily parse it. Is there a way to convert that data to something consistent like &#8220;Comma Separated?&#8221;<\/p>\n<p><img decoding=\"async\" width=\"34\" height=\"34\" class=\"wp-image-86279\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/08\/word-image-2.jpeg\" \/><\/p>\n<p>Why yes you can! This is something that is easily done with a regular expression. Using a simple example like this will identify all content with more than one blank space separating it, and replace it with a comma!<\/p>\n<p><strong>$SampleText=&#8217;Hello \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 This \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 is \u00a0 your \u00a0 \u00a0\u00a0 Good \u00a0\u00a0 Friend \u00a0 \u00a0 Doctor \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Scripto&#8217;<\/strong>\n<strong>$SampleText -replace &#8216;\\s{2,}&#8217; , &#8216;,&#8217;<\/strong><\/p>\n<p><img decoding=\"async\" width=\"96\" height=\"145\" class=\"wp-image-86280\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/08\/word-image-2.png\" \/><\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Your good friend, Doctor Scripto<\/strong><\/p>\n<p>PowerShell, Doctor Scripto, PowerTip, Dan Reist, Regular Expressions<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Using PowerShell and a very simple Regular Expression to convert Random counts of spaces to a Comma Hey Doctor Scripto! I have some string based output from a non PowerShell application. The output is good but I need to easily parse it. Is there a way to convert that data to something consistent like [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1930,1739,1738,687],"tags":[1931,1740,377,356,174],"class_list":["post-86277","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-200-level","category-doctor-scripto","category-powershell","category-regular-expressions","tag-dan-reist","tag-doctor-scripto","tag-powershell","tag-powertip","tag-regular-expressions"],"acf":[],"blog_post_summary":"<p>Summary: Using PowerShell and a very simple Regular Expression to convert Random counts of spaces to a Comma Hey Doctor Scripto! I have some string based output from a non PowerShell application. The output is good but I need to easily parse it. Is there a way to convert that data to something consistent like [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=86277"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86277\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=86277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=86277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=86277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}