{"id":1505,"date":"2015-11-01T01:33:43","date_gmt":"2015-11-01T09:33:43","guid":{"rendered":"http:\/\/systemsolver.com\/StatlerBlog\/?p=1505"},"modified":"2015-11-01T01:33:43","modified_gmt":"2015-11-01T09:33:43","slug":"linux-bash-script-read-through-file-tab-delimited","status":"publish","type":"post","link":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/2015\/11\/01\/linux-bash-script-read-through-file-tab-delimited\/","title":{"rendered":"Linux Bash script read through file tab delimited"},"content":{"rendered":"<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">This bash file will create hard links from a tab delimited text file that declares on each row the source and hard link destination<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">To run such a bash file:<br \/>\nCreate a new document.<br \/>\nWhat ever name, end in .sh<br \/>\nRight-click, select properties\/ make executable change permissions if needed<br \/>\nAlways start such a file with #!\/bin\/bash<br \/>\nTo run the file type: sh dir\/file.sh<\/p>\n<pre style=\"color: black ! important; padding-left: 60px;\" data-blkn-colour=\"rgba(51,51,51,1)\">#!\/bin\/bash\n\n# Opens a text file, reads each line\n#\u00a0\u00a0\u00a0\u00a0 Each line in the text file has two items separated by tab\n#\u00a0\u00a0\u00a0\u00a0 First item is the SourceFile (SF)\n#\u00a0\u00a0\u00a0\u00a0 Second item is the destination folder and name to put the hard link (DL)\n# Creates a hard link with line's parameters\n# read -r, the -r says to not allow backslashes to escape any characters\n#\u00a0\u00a0\u00a0\u00a0 http:\/\/linuxcommand.org\/lc3_pages\/readh.html\n\nfilename='\/media\/Office-Files\/Files\/create_links.log' \u00a0\u00a0 \u00a0# variable to set text file.\nIFS=\"\u00a0\u00a0 \u00a0\" \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0# set read to separate with tabs (between double quotes is an actual tab from the keyboard).\nwhile read -r SF DL ; do \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0# read each line in the text file and assign variable to each item.\n\u00a0\u00a0 \u00a0ln\u00a0 \"$SF\" \"$DL\"\u00a0 2&gt;&gt; errors.txt\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0# create hard link using variables from text file.\n\ndone &lt; \"$filename\" \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0# strange that the text file name is put at the end, but it is.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This bash file will create hard links from a tab delimited text file that declares on each row the source and hard link destination To run such a bash file: Create a new document. What ever name, end in .sh Right-click, select properties\/ make executable change permissions if needed Always start such a file with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6],"tags":[],"class_list":["post-1505","post","type-post","status-publish","format-standard","hentry","category-general","category-linux"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/comments?post=1505"}],"version-history":[{"count":0,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1505\/revisions"}],"wp:attachment":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/media?parent=1505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/categories?post=1505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/tags?post=1505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}