{"id":9154,"date":"2019-02-27T17:23:26","date_gmt":"2019-02-27T22:23:26","guid":{"rendered":"https:\/\/www.ezrasf.com\/wplog\/?p=9154"},"modified":"2019-02-27T16:29:29","modified_gmt":"2019-02-27T21:29:29","slug":"convert-little-endian-utf-16-to-ascii","status":"publish","type":"post","link":"https:\/\/www.ezrasf.com\/wplog\/2019\/02\/27\/convert-little-endian-utf-16-to-ascii\/","title":{"rendered":"Convert Little-endian UTF-16 to ASCII"},"content":{"rendered":"<figure id=\"attachment_media-33\" aria-describedby=\"caption-attachment-media-33\" style=\"width: 394px\" class=\"wp-caption alignright\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"9155\" data-permalink=\"https:\/\/www.ezrasf.com\/wplog\/pexels-photo-193349\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.ezrasf.com\/wplog\/wp-content\/uploads\/2019\/02\/pexels-photo-193349.jpeg?fit=867%2C1300&amp;ssl=1\" data-orig-size=\"867,1300\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"hacker screen\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Photo by Markus Spiske temporausch.com on &lt;a href=&quot;https:\/\/www.pexels.com\/photo\/hacker-screen-193349\/&quot; rel=&quot;nofollow&quot;&gt;Pexels.com&lt;\/a&gt;&lt;\/p&gt;\n\" data-large-file=\"https:\/\/i0.wp.com\/www.ezrasf.com\/wplog\/wp-content\/uploads\/2019\/02\/pexels-photo-193349.jpeg?fit=683%2C1024&amp;ssl=1\" class=\"alignnone  wp-image-9155\" src=\"https:\/\/i0.wp.com\/www.ezrasf.com\/wplog\/wp-content\/uploads\/2019\/02\/pexels-photo-193349.jpeg?resize=394%2C590&#038;ssl=1\" alt=\"hacker screen\" width=\"394\" height=\"590\" srcset=\"https:\/\/i0.wp.com\/www.ezrasf.com\/wplog\/wp-content\/uploads\/2019\/02\/pexels-photo-193349.jpeg?w=867&amp;ssl=1 867w, https:\/\/i0.wp.com\/www.ezrasf.com\/wplog\/wp-content\/uploads\/2019\/02\/pexels-photo-193349.jpeg?resize=250%2C375&amp;ssl=1 250w, https:\/\/i0.wp.com\/www.ezrasf.com\/wplog\/wp-content\/uploads\/2019\/02\/pexels-photo-193349.jpeg?resize=768%2C1152&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.ezrasf.com\/wplog\/wp-content\/uploads\/2019\/02\/pexels-photo-193349.jpeg?resize=683%2C1024&amp;ssl=1 683w\" sizes=\"auto, (max-width: 394px) 100vw, 394px\" \/><figcaption id=\"caption-attachment-media-33\" class=\"wp-caption-text\">Photo by Markus Spiske temporausch.com on <a href=\"https:\/\/www.pexels.com\/photo\/hacker-screen-193349\/\" rel=\"nofollow\">Pexels.com<\/a><\/figcaption><\/figure>\n<p>I generated some text files working with Get-Acl Powershell, but I did not know how to get Powershell to do some advanced features. (Basically, I wanted to the Select-String to include the next 2 lines and see whether a specific group was in that list. And maybe some exclusions.) So, I copied the files over to my Linux home to check there.<\/p>\n<p>The basic most grep? Nothing.<\/p>\n<p>I used ls -l and confirmed they have data. I used less to confirm I can see it.<\/p>\n<p>I copied a string and did a grep for it. Nothing.<\/p>\n<p>I did a dos2unix. That didn&#8217;t fix it. Finally, I did:<\/p>\n<pre>file filename.txt<\/pre>\n<p>That revealed the files had types of:<\/p>\n<ol>\n<li>Original: Little-endian UTF-16 Unicode text, with CRLF line terminators<\/li>\n<li>dos2unix converted: Little-endian UTF-16 Unicode text<\/li>\n<\/ol>\n<p>Basically, this told me that the dos2unix fixed one problem but not both. The &#8220;with CRLF line terminators&#8221; means that Windows and Unix have philosophical differences in how to format text lines.<\/p>\n<p>Little-endian is a geeky homage to Gulliver&#8217;s travels. It has to do with which direction one encodes the bits. But, it isn&#8217;t really the big problem here. UTF-16 is the problem because apparently, I need it to be UTF-8 for grep to read it. So, the fix is to use an encoding converting:<\/p>\n<pre>iconv -f utf-16 -t utf-8 filename.txt &gt; filename_new.txt<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I generated some text files working with Get-Acl Powershell, but I did not know how to get Powershell to do some advanced features. (Basically, I wanted to the Select-String to include the next 2 lines and see whether a specific group was in that list. And maybe some exclusions.) So, I copied the files over [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[621,109],"tags":[3441,3444,3442,3443,3445,839,3439,2784,3440],"class_list":["post-9154","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-unix","tag-ascii","tag-dos2unix","tag-get-acl","tag-grep","tag-iconv","tag-linux","tag-little-endian","tag-powershell","tag-utf-16"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1rUBW-2nE","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ezrasf.com\/wplog\/wp-json\/wp\/v2\/posts\/9154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ezrasf.com\/wplog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ezrasf.com\/wplog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ezrasf.com\/wplog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ezrasf.com\/wplog\/wp-json\/wp\/v2\/comments?post=9154"}],"version-history":[{"count":0,"href":"https:\/\/www.ezrasf.com\/wplog\/wp-json\/wp\/v2\/posts\/9154\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ezrasf.com\/wplog\/wp-json\/wp\/v2\/media?parent=9154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ezrasf.com\/wplog\/wp-json\/wp\/v2\/categories?post=9154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ezrasf.com\/wplog\/wp-json\/wp\/v2\/tags?post=9154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}