{"id":7074,"date":"2010-03-01T08:10:06","date_gmt":"2010-03-01T07:10:06","guid":{"rendered":"https:\/\/www.dreamsworld.it\/emanuele\/?p=7074"},"modified":"2010-03-01T00:15:23","modified_gmt":"2010-02-28T23:15:23","slug":"script-bash-per-il-totale-della-propria-spesa-mensile-o","status":"publish","type":"post","link":"https:\/\/www.dreamsworld.it\/emanuele\/2010-03-01\/script-bash-per-il-totale-della-propria-spesa-mensile-o\/","title":{"rendered":"Script bash per il totale della propria spesa mensile :o)"},"content":{"rendered":"<p>Era fine mese, dovevo tirar le somme delle mie <a title=\"Ingressi e uscite.\" href=\"\/\/www.dreamsworld.it\/emanuele\/2010-02-27\/ingressi-e-uscite\/\">spese mensili<\/a> e non mi andava &#8211; minimamente &#8211; di <strong>prender la calcolatrice<\/strong> e iniziare a scrivere le cifre, una per una col rischio di saltarne qualcuna, cos\u00ec ho aperto un editor di testo e ho scritto questo <em>misero<\/em> <strong>script in bash<\/strong> per calcolare la spesa totale.<\/p>\n<pre lang=\"bash\" line=\"1\">#!\/bin\/sh\r\ncat ~\/Documents\/spesa_mensile.txt | awk -F\u20ac '\/^[^a-z,A-Z].[^+]*$\/ { spesa += $1 }\r\n{ if(NR==1) mese=$1\r\nif (mese == \"NOVEMBRE\" || mese==\"APRILE\" || mese==\"GIUGNO\" || mese==\"SETTEMBRE\") giorni=\"30\"\r\n\tif (mese == \"FEBBRAIO\") giorni=\"28\"\r\n\t\telse giorni=\"31\"\r\n}\r\nEND { print \"La somma per il mese di\", mese, \"\u00e8\", spesa, \"\u20ac...\\nLa spesa media \u00e8 di\", spesa\/giorni,\"\u20ac al giorno.\" }'<\/pre>\n<p>Ogni mese mi basta scrivere un file in questo modo:<\/p>\n<pre lang=\"txt\" line=\"1\">FEBBRAIO\r\n0,10 \u20ac Busta lettera\r\n0,60 \u20ac Francobollo\r\n4,5 \u20ac Carne\r\n11,65 \u20ac Spesa GS\r\n0,80 \u20ac Pane\r\n5 \u20ac benzina Vespa<\/pre>\n<p>Il risultato \u00e8 <em>a portata di shell<\/em>&#8230;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.dreamsworld.it\/emanuele\/wp-content\/uploads\/2010\/03\/2010-03-01_script_bash_spesa.png\" alt=\"Script bash per il calcolo della spesa mensile\" width=\"615\" height=\"244\" class=\"attachment wp-att-7075 centered\" \/><\/p>\n<p>Il fatto \u00e8 che un ingegnere informatico non prende la calcolatrice. La crea. \ud83d\ude09<\/p>\n<p><strong>Emanuele<\/strong><\/p>\n<p>PS: se volete usarlo tenete a mente che <strong>la prima riga<\/strong> va riservata al mese (<em>lo script la usa per riconoscere i giorni di cui \u00e8 composto per effettuare la media<\/em>) per il resto potete scrivere ci\u00f2 che volete basta che usate quell&#8217;ordine e che nominiate il file <em>spesa_mensile.txt<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Era fine mese, dovevo tirar le somme delle mie spese mensili e non mi andava &#8211; minimamente &#8211; di prender la calcolatrice e iniziare a scrivere le cifre, una per una col rischio di saltarne qualcuna, cos\u00ec ho aperto un &hellip; <a href=\"https:\/\/www.dreamsworld.it\/emanuele\/2010-03-01\/script-bash-per-il-totale-della-propria-spesa-mensile-o\/\">Leggi ancora &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_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":""},"categories":[3,1],"tags":[863,1913,1650,33,1064,1582,462,1096,662,245,1143],"class_list":["post-7074","post","type-post","status-publish","format-standard","hentry","category-computer","category-all-day","tag-awk","tag-bash","tag-contare","tag-informatica","tag-ingegnere","tag-programmare","tag-resoconto","tag-script","tag-shell","tag-soldi","tag-spesa"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/posts\/7074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/comments?post=7074"}],"version-history":[{"count":0,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/posts\/7074\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/media?parent=7074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/categories?post=7074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/tags?post=7074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}