{"id":252,"date":"2010-05-03T06:40:34","date_gmt":"2010-05-03T06:40:34","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/05\/03\/reading-xml-file-using-shell-script\/"},"modified":"2021-02-27T09:53:56","modified_gmt":"2021-02-27T09:53:56","slug":"reading-xml-file-using-shell-script","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/","title":{"rendered":"How to read XML file by using shell script ?"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4367 aligncenter\" src=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/05\/xml-file-using-shell-script.png\" alt=\"read-xml-file-using-shell-script\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/05\/xml-file-using-shell-script.png 600w, https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/05\/xml-file-using-shell-script-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>This was like the first time where I had to write something that will be able to read something out of a XML file using a shell script. Usually I would use Python\/Perl as my favorite choices in such a scenario but in this one I really *had* to do all within a shell script.<\/p>\n<p>This is an example of the type of XML file I had to read:<\/p>\n<p><code>Fixed a new bug<br \/>\nShoaib Mir<br \/>\nSun, 02 May 2010<br \/>\nshoaibmir[@]gmail.com<\/code><\/p>\n<p>I ended up having a shell script like this:<br \/>\n<code><br \/>\n#!\/bin\/bash<\/code><\/p>\n<p><code>#Looking for four keywords in here<br \/>\nfor key in changelog name date email<br \/>\ndo<br \/>\nOUTPT=`grep  $key log.xml | tr -d '\\t' | sed 's\/^\\([^&lt;].*\\)$\/\\1\/' `<br \/>\neval ${key}=`echo -ne \\\"\"${OUTPT}\"\\\"`<br \/>\ndone<\/code><\/p>\n<p># Getting the results in four specific arrays<br \/>\nchangelogarr=( `echo ${changelog}` )<br \/>\nnamearr=( `echo ${name}` )<br \/>\ndatearr=( `echo ${date}` )<br \/>\nemailarr=( `echo ${email}` )<\/p>\n<p><code>#Print all Arrays<br \/>\necho ${changelogarr[@]}<br \/>\necho ${namearr[@]}<br \/>\necho ${datearr[@]}<br \/>\necho ${emailarr[@]}<br \/>\n<\/code><\/p>\n<p>Which gives me an output:<br \/>\n<code><br \/>\nshoaib@shoaib-desktop:~\/Desktop$ .\/readxml.sh<br \/>\nFixed a new bug Shoaib Mir<br \/>\nSun, 02 May 2010<br \/>\nshoaibmir[@]gmail.com<\/code><\/p>\n<p>&nbsp;<\/p>\n<p><b>Reference:<\/b><\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"cc6RXB1pS5\"><p><a href=\"https:\/\/shoaibmir.wordpress.com\/2010\/05\/02\/reading-xml-file-using-shell-scripting\/\">Reading XML file using shell&nbsp;script<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;Reading XML file using shell&nbsp;script&#8221; &#8212; Life in the fast lane...\" src=\"https:\/\/shoaibmir.wordpress.com\/2010\/05\/02\/reading-xml-file-using-shell-scripting\/embed\/#?secret=UX3iRl5qM9#?secret=cc6RXB1pS5\" data-secret=\"cc6RXB1pS5\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This was like the first time where I had to write something that will be able to read something out [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":4367,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[454],"tags":[349,1122,3113,1806,593,4115,4116,4120,4118,278,138,3046,4119,1927,524,4117],"class_list":["post-252","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-shell-script","tag-file","tag-guide","tag-how-to","tag-instruction","tag-process","tag-read","tag-read-xml-file","tag-read-xml-file-using-shell-script","tag-read-xml-with-shell-script","tag-script","tag-shell","tag-shell-script","tag-shell-script-for-reading-xml-content","tag-using","tag-xml","tag-xml-file-reading-by-shell-script"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to read XML file by using shell script ? - scmGalaxy<\/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:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to read XML file by using shell script ? - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"This was like the first time where I had to write something that will be able to read something out [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2010-05-03T06:40:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-27T09:53:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/05\/xml-file-using-shell-script.png\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"scmgalaxy K\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"scmgalaxy K\" \/>\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:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/\"},\"author\":{\"name\":\"scmgalaxy K\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/fc12ad190f540e79460243c81148d102\"},\"headline\":\"How to read XML file by using shell script ?\",\"datePublished\":\"2010-05-03T06:40:34+00:00\",\"dateModified\":\"2021-02-27T09:53:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/\"},\"wordCount\":120,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2010\\\/05\\\/xml-file-using-shell-script.png\",\"keywords\":[\"File\",\"Guide\",\"How To\",\"Instruction\",\"Process\",\"Read\",\"Read XML File\",\"Read XML file using shell script\",\"Read XML with Shell Script\",\"script\",\"Shell\",\"Shell script\",\"shell script for reading xml content\",\"Using\",\"xml\",\"XML File Reading by Shell script\"],\"articleSection\":[\"Shell Script\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/\",\"name\":\"How to read XML file by using shell script ? - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2010\\\/05\\\/xml-file-using-shell-script.png\",\"datePublished\":\"2010-05-03T06:40:34+00:00\",\"dateModified\":\"2021-02-27T09:53:56+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/fc12ad190f540e79460243c81148d102\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2010\\\/05\\\/xml-file-using-shell-script.png\",\"contentUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2010\\\/05\\\/xml-file-using-shell-script.png\",\"width\":600,\"height\":400,\"caption\":\"read-xml-file-using-shell-script\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/reading-xml-file-using-shell-script\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to read XML file by using shell script ?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/fc12ad190f540e79460243c81148d102\",\"name\":\"scmgalaxy K\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g\",\"caption\":\"scmgalaxy K\"},\"sameAs\":[\"http:\\\/\\\/www.DevOpsSchool.com\"],\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/scmgalaxy\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to read XML file by using shell script ? - scmGalaxy","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:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/","og_locale":"en_US","og_type":"article","og_title":"How to read XML file by using shell script ? - scmGalaxy","og_description":"This was like the first time where I had to write something that will be able to read something out [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/","og_site_name":"scmGalaxy","article_published_time":"2010-05-03T06:40:34+00:00","article_modified_time":"2021-02-27T09:53:56+00:00","og_image":[{"width":600,"height":400,"url":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/05\/xml-file-using-shell-script.png","type":"image\/png"}],"author":"scmgalaxy K","twitter_card":"summary_large_image","twitter_misc":{"Written by":"scmgalaxy K","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/"},"author":{"name":"scmgalaxy K","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/fc12ad190f540e79460243c81148d102"},"headline":"How to read XML file by using shell script ?","datePublished":"2010-05-03T06:40:34+00:00","dateModified":"2021-02-27T09:53:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/"},"wordCount":120,"commentCount":0,"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/05\/xml-file-using-shell-script.png","keywords":["File","Guide","How To","Instruction","Process","Read","Read XML File","Read XML file using shell script","Read XML with Shell Script","script","Shell","Shell script","shell script for reading xml content","Using","xml","XML File Reading by Shell script"],"articleSection":["Shell Script"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/","name":"How to read XML file by using shell script ? - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/#primaryimage"},"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/05\/xml-file-using-shell-script.png","datePublished":"2010-05-03T06:40:34+00:00","dateModified":"2021-02-27T09:53:56+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/fc12ad190f540e79460243c81148d102"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/#primaryimage","url":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/05\/xml-file-using-shell-script.png","contentUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/05\/xml-file-using-shell-script.png","width":600,"height":400,"caption":"read-xml-file-using-shell-script"},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/reading-xml-file-using-shell-script\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"How to read XML file by using shell script ?"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/fc12ad190f540e79460243c81148d102","name":"scmgalaxy K","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g","caption":"scmgalaxy K"},"sameAs":["http:\/\/www.DevOpsSchool.com"],"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/scmgalaxy\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=252"}],"version-history":[{"count":2,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"predecessor-version":[{"id":4368,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/252\/revisions\/4368"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media\/4367"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}