{"id":635,"date":"2023-04-28T15:13:19","date_gmt":"2023-04-28T22:13:19","guid":{"rendered":"https:\/\/liangqi.org\/?p=635"},"modified":"2023-04-28T15:16:11","modified_gmt":"2023-04-28T22:16:11","slug":"handy-bash-command","status":"publish","type":"post","link":"https:\/\/liangqi.org\/?p=635","title":{"rendered":"Handy Bash Command"},"content":{"rendered":"\n<p>It always very handy to know a little bit bash to do file operation. E.G. generate SQL by csv.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Convert csv to a SQL:<\/h2>\n\n\n\n<p>Input<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>289104,4cca04f6-2b72-4e28-b3c2-052bad0d61bb,b40522d5-707e-4d8c-959b-b1f9f88cca1b,1e9a82bd-7b3b-4d38-99ef-fbfb558987ce\n289948,4cca04f6-2b72-4e28-b3c2-052bad0d61bb,803cf363-7132-43ed-b213-7e127ecf7141,16a109ba-478c-4511-b8a3-e75126cd7f9a<\/code><\/pre>\n\n\n\n<p>Script<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\ninput=\"\/Users\/lwang2\/Downloads\/changeUUID.csv\"\nwhile read -r line\ndo\n\tvar_uuid=$(echo $line | cut -d \",\" -f 4)\n\techo $var_uuid\n\tvar_id=$(echo $line | cut -d \",\" -f 1)\n\techo $var_id\n\techo UPDATE STORE SET store_uuid='\"'\"$var_uuid\"'\"' WHERE id=\"$var_id\"\";\" &gt;&gt; updateUUID.sql\ndone &lt; \"$input\"<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE STORE SET store_uuid=\"1e9a82bd-7b3b-4d38-99ef-fbfb558987ce\" WHERE id=289104;\nUPDATE STORE SET store_uuid=\"16a109ba-478c-4511-b8a3-e75126cd7f9a\" WHERE id=289948;<\/code><\/pre>\n\n\n\n<p>Notes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>the the pipe result we need $(echo XX) to put the result to a variable.<\/li>\n\n\n\n<li>Split string and get one sub string by position.<\/li>\n\n\n\n<li>To output double quote in the output, we need the two single quote.<\/li>\n\n\n\n<li>Append a new file using <code>&gt;&gt;<\/code>.<\/li>\n\n\n\n<li>It seems there is but the last line doesn&#8217;t output. <\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Generate UUID and convert big case to small case<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\ninput=\"\/Users\/lwang2\/Downloads\/POYNT.csv\"\nwhile read -r line\ndo\n\tuuid=$(uuidgen)\n\techo \"$line\"\"$uuid\" | awk '{print tolower($0)}' &gt;&gt; result.csv\ndone &lt; \"$input\"<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>It always very handy to know a little bit bash to do file operation. E.G. generate SQL by csv. Convert csv to a SQL: Input Script Output Notes: Generate UUID and convert big case to small case<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,16],"tags":[],"class_list":["post-635","post","type-post","status-publish","format-standard","hentry","category-linux","category-16"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Handy Bash Command - Liangqi\u2018s Technical Journey<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/liangqi.org\/?p=635\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Handy Bash Command - Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"og:description\" content=\"It always very handy to know a little bit bash to do file operation. E.G. generate SQL by csv. Convert csv to a SQL: Input Script Output Notes: Generate UUID and convert big case to small case\" \/>\n<meta property=\"og:url\" content=\"https:\/\/liangqi.org\/?p=635\" \/>\n<meta property=\"og:site_name\" content=\"Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-28T22:13:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-28T22:16:11+00:00\" \/>\n<meta name=\"author\" content=\"liangqi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"liangqi\" \/>\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\":\"Article\",\"@id\":\"https:\/\/liangqi.org\/?p=635#article\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/?p=635\"},\"author\":{\"name\":\"liangqi\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"headline\":\"Handy Bash Command\",\"datePublished\":\"2023-04-28T22:13:19+00:00\",\"dateModified\":\"2023-04-28T22:16:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/liangqi.org\/?p=635\"},\"wordCount\":94,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"articleSection\":[\"Linux\",\"\u6280\u672f\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/liangqi.org\/?p=635#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/liangqi.org\/?p=635\",\"url\":\"https:\/\/liangqi.org\/?p=635\",\"name\":\"Handy Bash Command - Liangqi\u2018s Technical Journey\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/#website\"},\"datePublished\":\"2023-04-28T22:13:19+00:00\",\"dateModified\":\"2023-04-28T22:16:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/liangqi.org\/?p=635#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/liangqi.org\/?p=635\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/liangqi.org\/?p=635#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/liangqi.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Handy Bash Command\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/liangqi.org\/#website\",\"url\":\"https:\/\/liangqi.org\/\",\"name\":\"Liangqi\u2018s Technical Journey\",\"description\":\"Chasing Excellence; Enjoy life.\",\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/liangqi.org\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\",\"name\":\"liangqi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"contentUrl\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"width\":2560,\"height\":1920,\"caption\":\"liangqi\"},\"logo\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/liangqi.org\"],\"url\":\"https:\/\/liangqi.org\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Handy Bash Command - Liangqi\u2018s Technical Journey","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:\/\/liangqi.org\/?p=635","og_locale":"en_US","og_type":"article","og_title":"Handy Bash Command - Liangqi\u2018s Technical Journey","og_description":"It always very handy to know a little bit bash to do file operation. E.G. generate SQL by csv. Convert csv to a SQL: Input Script Output Notes: Generate UUID and convert big case to small case","og_url":"https:\/\/liangqi.org\/?p=635","og_site_name":"Liangqi\u2018s Technical Journey","article_published_time":"2023-04-28T22:13:19+00:00","article_modified_time":"2023-04-28T22:16:11+00:00","author":"liangqi","twitter_card":"summary_large_image","twitter_misc":{"Written by":"liangqi","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/liangqi.org\/?p=635#article","isPartOf":{"@id":"https:\/\/liangqi.org\/?p=635"},"author":{"name":"liangqi","@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"headline":"Handy Bash Command","datePublished":"2023-04-28T22:13:19+00:00","dateModified":"2023-04-28T22:16:11+00:00","mainEntityOfPage":{"@id":"https:\/\/liangqi.org\/?p=635"},"wordCount":94,"commentCount":0,"publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"articleSection":["Linux","\u6280\u672f"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/liangqi.org\/?p=635#respond"]}]},{"@type":"WebPage","@id":"https:\/\/liangqi.org\/?p=635","url":"https:\/\/liangqi.org\/?p=635","name":"Handy Bash Command - Liangqi\u2018s Technical Journey","isPartOf":{"@id":"https:\/\/liangqi.org\/#website"},"datePublished":"2023-04-28T22:13:19+00:00","dateModified":"2023-04-28T22:16:11+00:00","breadcrumb":{"@id":"https:\/\/liangqi.org\/?p=635#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/liangqi.org\/?p=635"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/liangqi.org\/?p=635#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/liangqi.org\/"},{"@type":"ListItem","position":2,"name":"Handy Bash Command"}]},{"@type":"WebSite","@id":"https:\/\/liangqi.org\/#website","url":"https:\/\/liangqi.org\/","name":"Liangqi\u2018s Technical Journey","description":"Chasing Excellence; Enjoy life.","publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/liangqi.org\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3","name":"liangqi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/","url":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","contentUrl":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","width":2560,"height":1920,"caption":"liangqi"},"logo":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/liangqi.org"],"url":"https:\/\/liangqi.org\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=635"}],"version-history":[{"count":2,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/635\/revisions"}],"predecessor-version":[{"id":637,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/635\/revisions\/637"}],"wp:attachment":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}