{"id":78,"date":"2018-12-29T07:09:31","date_gmt":"2018-12-29T07:09:31","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=78"},"modified":"2018-12-29T07:09:39","modified_gmt":"2018-12-29T07:09:39","slug":"sum-data-in-columns-in-a-fixed-width-text-file","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/sum-data-in-columns-in-a-fixed-width-text-file\/","title":{"rendered":"Sum data in columns in a fixed width text file"},"content":{"rendered":"<pre>declare -i SW=0 SX=0 SY=0 SZ=0\nwhile IFS='' read LINE; do\n    SW+=${LINE:0:5} ; SX+=${LINE:5:5}\n    SY+=${LINE:10:5} ; SZ+=${LINE:15:5}\ndone &lt; sample.txt\nprintf \" %4d %4d %4d %4d\\n\" $S{W,X,Y,Z}<\/pre>\n<p>#sample.txt<\/p>\n<pre>0 1 2 3\n0 1 2 3\n0 1 2 3\n0 1 2 3\n0 1 2 3\n1 1 1 1<\/pre>\n<p>#result:<\/p>\n<pre> 1 6 11 16<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>declare -i SW=0 SX=0 SY=0 SZ=0 while IFS=&#8221; read LINE; do SW+=${LINE:0:5} ; SX+=${LINE:5:5} SY+=${LINE:10:5} ; SZ+=${LINE:15:5} done &lt; sample.txt printf &#8221; %4d %4d %4d %4d\\n&#8221; $S{W,X,Y,Z} #sample.txt 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 1 1 1 1 #result: 1 6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","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,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-78","post","type-post","status-publish","format-standard","hentry","category-bash"],"modified_by":null,"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-1g","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":886,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/02\/157-formatting-output-in-awk\/","url_meta":{"origin":78,"position":0},"title":"#157 Formatting output in awk","author":"gantovnik","date":"2021-02-09","format":false,"excerpt":"#157 Formatting output in awk Without formatting, the command look like this The same command with formatting With the header information added to the BEGIN block:","rel":"","context":"In &quot;awk&quot;","block_context":{"text":"awk","link":"https:\/\/gantovnik.com\/bio-tips\/category\/awk\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":892,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/02\/159-awk-control-file\/","url_meta":{"origin":78,"position":1},"title":"#159 Awk control file","author":"gantovnik","date":"2021-02-09","format":false,"excerpt":"#159 Awk control file Create awk control file func1.awk Command to run awk control file is","rel":"","context":"In &quot;awk&quot;","block_context":{"text":"awk","link":"https:\/\/gantovnik.com\/bio-tips\/category\/awk\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":671,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/09\/114-python-script-for-remove-offsets-from-cbar-elements\/","url_meta":{"origin":78,"position":2},"title":"#114: Python script for remove offsets from CBAR elements","author":"gantovnik","date":"2020-09-28","format":false,"excerpt":"#114: Python script for remove offsets from CBAR elements SOL 106 does not allow offsets in CBAR elements.","rel":"","context":"In &quot;nastran&quot;","block_context":{"text":"nastran","link":"https:\/\/gantovnik.com\/bio-tips\/category\/nastran\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":413,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/03\/perl-script-to-write-line-containing-specific-word-and-next-second-and-third-lines\/","url_meta":{"origin":78,"position":3},"title":"#62 Perl script to write line containing specific word and next second and third lines","author":"gantovnik","date":"2019-03-10","format":false,"excerpt":"","rel":"","context":"In &quot;perl&quot;","block_context":{"text":"perl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/perl\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":943,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/09\/170-gets-the-distance-of-the-given-point-from-the-nearest-line-with-ids-specified-as-arguments-in-hypermesh-tcl\/","url_meta":{"origin":78,"position":4},"title":"#170 Gets the distance of the given point from the nearest line with IDs specified as arguments in HyperMesh tcl","author":"gantovnik","date":"2021-09-01","format":false,"excerpt":"#170 Gets the distance of the given point from the nearest line with IDs specified as arguments in HyperMesh tcl. To get closest to the point with coordinates (10, 20, 30) point on the line with ID 13: To get closest line from the set with IDs 13 14 15:\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2065,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/01\/408-animated-line-plot-in-python\/","url_meta":{"origin":78,"position":5},"title":"#408 Animated line plot in python","author":"gantovnik","date":"2024-01-14","format":false,"excerpt":"","rel":"","context":"In &quot;animation&quot;","block_context":{"text":"animation","link":"https:\/\/gantovnik.com\/bio-tips\/category\/animation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex408-1.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex408-1.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex408-1.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=78"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/78\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}