{"id":8,"date":"2022-09-17T22:56:27","date_gmt":"2022-09-17T22:56:27","guid":{"rendered":"https:\/\/reynhartono.com\/?p=8"},"modified":"2022-09-18T18:15:06","modified_gmt":"2022-09-18T18:15:06","slug":"counting-non-null-bytes-of-a-file","status":"publish","type":"post","link":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/","title":{"rendered":"Counting Non-Null Bytes of a File"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The simplest form to count non-null bytes of a file is by using <code>sed<\/code> to delete the null bytes and then pipe it to <code>wc<\/code>. This will achieve our main goal to count the non-null bytes of a file. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"wpcustom\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sed 's\/\\x00\/\/g' \/path\/to\/file | wc -c<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But, when trying to do the counting on large files, that command will take forever and it doesn&#8217;t even give any progress. So we can start using <code>pv<\/code> to be able to see the progress. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"wpcustom\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pv \/path\/to\/file | sed 's\/\\x00\/\/g' | wc -c<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;ll tell us how many bytes has been processed and the overall progress of the command. But, if you wanted to get more detail of the progress, we can put two <code>pv<\/code> in the command. This will give us the overall progress and the counted non-null bytes. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"wpcustom\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pv -N in -c \/path\/to\/file | sed 's\/\\x00\/\/g' | pv -N out -c | wc -c<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>in<\/code> part of <code>pv<\/code> will give us the overall progress and <code>out<\/code> is the counted non-null bytes. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The simplest form to count non-null bytes of a file is by using sed to delete the null bytes and then pipe it to wc. This will achieve our main goal to count the non-null&hellip;<\/p>\n<p><a href=\"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/\" class=\"more-link\">Read more<span class=\"screen-reader-text\"> of Counting Non-Null Bytes of a File<\/span><span aria-hidden=\"true\"> &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[15],"tags":[11,12,10],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-engineering","tag-bash","tag-binary","tag-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Counting Non-Null Bytes of a File - Reyn Hartono<\/title>\n<meta name=\"description\" content=\"How to count non-null bytes of a file binary content by using sed and wc command on Linux.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Counting Non-Null Bytes of a File - Reyn Hartono\" \/>\n<meta property=\"og:description\" content=\"How to count non-null bytes of a file binary content by using sed and wc command on Linux.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/\" \/>\n<meta property=\"og:site_name\" content=\"Reyn Hartono\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-17T22:56:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-18T18:15:06+00:00\" \/>\n<meta name=\"author\" content=\"Reynaldi Hartono\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ReynHartono\" \/>\n<meta name=\"twitter:site\" content=\"@ReynHartono\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Reynaldi Hartono\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/counting-non-null-bytes-of-a-file\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/counting-non-null-bytes-of-a-file\\\/\"},\"author\":{\"name\":\"Reynaldi Hartono\",\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/#\\\/schema\\\/person\\\/aa0ff7e8623b6dcff6b11bb24fc7a840\"},\"headline\":\"Counting Non-Null Bytes of a File\",\"datePublished\":\"2022-09-17T22:56:27+00:00\",\"dateModified\":\"2022-09-18T18:15:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/counting-non-null-bytes-of-a-file\\\/\"},\"wordCount\":140,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/#\\\/schema\\\/person\\\/aa0ff7e8623b6dcff6b11bb24fc7a840\"},\"keywords\":[\"bash\",\"binary\",\"linux\"],\"articleSection\":[\"Engineering\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/reyn.id\\\/blog\\\/counting-non-null-bytes-of-a-file\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/counting-non-null-bytes-of-a-file\\\/\",\"url\":\"https:\\\/\\\/reyn.id\\\/blog\\\/counting-non-null-bytes-of-a-file\\\/\",\"name\":\"Counting Non-Null Bytes of a File - Reyn Hartono\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/#website\"},\"datePublished\":\"2022-09-17T22:56:27+00:00\",\"dateModified\":\"2022-09-18T18:15:06+00:00\",\"description\":\"How to count non-null bytes of a file binary content by using sed and wc command on Linux.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/counting-non-null-bytes-of-a-file\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/reyn.id\\\/blog\\\/counting-non-null-bytes-of-a-file\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/counting-non-null-bytes-of-a-file\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/reyn.id\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Counting Non-Null Bytes of a File\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/reyn.id\\\/blog\\\/\",\"name\":\"Reyn Hartono\",\"description\":\"Personal Archive\",\"publisher\":{\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/#\\\/schema\\\/person\\\/aa0ff7e8623b6dcff6b11bb24fc7a840\"},\"alternateName\":\"reyn.id\\\/blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/reyn.id\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/reyn.id\\\/blog\\\/#\\\/schema\\\/person\\\/aa0ff7e8623b6dcff6b11bb24fc7a840\",\"name\":\"Reynaldi Hartono\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2b0ce59309f8767845c9ee1aa7d2514209bbd59483c1be632fff738d36509a2d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2b0ce59309f8767845c9ee1aa7d2514209bbd59483c1be632fff738d36509a2d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2b0ce59309f8767845c9ee1aa7d2514209bbd59483c1be632fff738d36509a2d?s=96&d=mm&r=g\",\"caption\":\"Reynaldi Hartono\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2b0ce59309f8767845c9ee1aa7d2514209bbd59483c1be632fff738d36509a2d?s=96&d=mm&r=g\"},\"sameAs\":[\"https:\\\/\\\/reyn.id\\\/blog\",\"https:\\\/\\\/www.instagram.com\\\/reynhartono\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/reynhartono\\\/\",\"https:\\\/\\\/x.com\\\/ReynHartono\"],\"url\":\"https:\\\/\\\/reyn.id\\\/blog\\\/author\\\/reyn\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Counting Non-Null Bytes of a File - Reyn Hartono","description":"How to count non-null bytes of a file binary content by using sed and wc command on Linux.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/","og_locale":"en_US","og_type":"article","og_title":"Counting Non-Null Bytes of a File - Reyn Hartono","og_description":"How to count non-null bytes of a file binary content by using sed and wc command on Linux.","og_url":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/","og_site_name":"Reyn Hartono","article_published_time":"2022-09-17T22:56:27+00:00","article_modified_time":"2022-09-18T18:15:06+00:00","author":"Reynaldi Hartono","twitter_card":"summary_large_image","twitter_creator":"@ReynHartono","twitter_site":"@ReynHartono","twitter_misc":{"Written by":"Reynaldi Hartono","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/#article","isPartOf":{"@id":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/"},"author":{"name":"Reynaldi Hartono","@id":"https:\/\/reyn.id\/blog\/#\/schema\/person\/aa0ff7e8623b6dcff6b11bb24fc7a840"},"headline":"Counting Non-Null Bytes of a File","datePublished":"2022-09-17T22:56:27+00:00","dateModified":"2022-09-18T18:15:06+00:00","mainEntityOfPage":{"@id":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/"},"wordCount":140,"commentCount":0,"publisher":{"@id":"https:\/\/reyn.id\/blog\/#\/schema\/person\/aa0ff7e8623b6dcff6b11bb24fc7a840"},"keywords":["bash","binary","linux"],"articleSection":["Engineering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/","url":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/","name":"Counting Non-Null Bytes of a File - Reyn Hartono","isPartOf":{"@id":"https:\/\/reyn.id\/blog\/#website"},"datePublished":"2022-09-17T22:56:27+00:00","dateModified":"2022-09-18T18:15:06+00:00","description":"How to count non-null bytes of a file binary content by using sed and wc command on Linux.","breadcrumb":{"@id":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/reyn.id\/blog\/counting-non-null-bytes-of-a-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/reyn.id\/blog\/"},{"@type":"ListItem","position":2,"name":"Counting Non-Null Bytes of a File"}]},{"@type":"WebSite","@id":"https:\/\/reyn.id\/blog\/#website","url":"https:\/\/reyn.id\/blog\/","name":"Reyn Hartono","description":"Personal Archive","publisher":{"@id":"https:\/\/reyn.id\/blog\/#\/schema\/person\/aa0ff7e8623b6dcff6b11bb24fc7a840"},"alternateName":"reyn.id\/blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/reyn.id\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/reyn.id\/blog\/#\/schema\/person\/aa0ff7e8623b6dcff6b11bb24fc7a840","name":"Reynaldi Hartono","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2b0ce59309f8767845c9ee1aa7d2514209bbd59483c1be632fff738d36509a2d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2b0ce59309f8767845c9ee1aa7d2514209bbd59483c1be632fff738d36509a2d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2b0ce59309f8767845c9ee1aa7d2514209bbd59483c1be632fff738d36509a2d?s=96&d=mm&r=g","caption":"Reynaldi Hartono"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/2b0ce59309f8767845c9ee1aa7d2514209bbd59483c1be632fff738d36509a2d?s=96&d=mm&r=g"},"sameAs":["https:\/\/reyn.id\/blog","https:\/\/www.instagram.com\/reynhartono\/","https:\/\/www.linkedin.com\/in\/reynhartono\/","https:\/\/x.com\/ReynHartono"],"url":"https:\/\/reyn.id\/blog\/author\/reyn\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":10,"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"predecessor-version":[{"id":56,"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions\/56"}],"wp:attachment":[{"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reyn.id\/blog\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}