{"id":366,"date":"2014-05-06T13:17:39","date_gmt":"2014-05-06T12:17:39","guid":{"rendered":"http:\/\/www.nax.cz\/?p=366"},"modified":"2014-05-06T13:17:39","modified_gmt":"2014-05-06T12:17:39","slug":"cut-config-to-pieces-using-awk-and-test-each-piece-separately","status":"publish","type":"post","link":"https:\/\/nax.cz\/?p=366","title":{"rendered":"Cut config to pieces using awk and test each piece separately"},"content":{"rendered":"<p>Not user friendly tools are horrible. It is usually consequence of not &#8222;eat your own dog food&#8220;. If the programmer doesn&#8217;t need to use the tool, then it is not very usable. Then you have to use some workaround.<\/p>\n<p>For instance just now. I have config file enumerating multiple files to load:<\/p>\n<p><code><br \/>\n\/\/some header<br \/>\nkey1=value<br \/>\nkey2= value<br \/>\n\/\/ file1<br \/>\nload=file_484<br \/>\nload.params=some params<br \/>\nload.subfile=file_696<br \/>\n\/\/ file2<br \/>\nload=file_837<br \/>\nload.params=some params<br \/>\nload.subfile=file_694<br \/>\n...<br \/>\n\/\/ file58<br \/>\nload=file_5928<br \/>\nload.params=some params<br \/>\nload.subfile=file_3847<br \/>\n<\/code><\/p>\n<p>Now when I run the tool, I get error that file is not compatible. But how to find out which file out of 58? One way would be to use strace tool to see which file it tries to open just before the error message. Unfortunately not an option in this case.<\/p>\n<p>So I used this trick:<br \/>\n1) cut config to 58 pieces<br \/>\n2) run tool with each config contain just one input file config<\/p>\n<p>First I used awk to cut original file to pieces. In vim I deleted &#8222;file<>&#8220; using command <code>:%s\/^\\\/\\\/.*$\/\\\/\\\/\/<\/code> and then I used 2 slash as a record separator:<br \/>\n<code><br \/>\nawk -v RS=\"\/\/\" 'BEGIN{i=10}{print $0 > \"piece\"i;i++}' input.txt<br \/>\n<\/code><\/p>\n<p>Then I run following bash cycle to iterate thru all the configs:<br \/>\n<code><br \/>\nfor f in piece*; do cat header.txt $f > script_input.conf; sh .\/script.sh script_input.conf; done<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not user friendly tools are horrible. It is usually consequence of not &#8222;eat your own dog food&#8220;. If the programmer doesn&#8217;t need to use the tool, then it is not very usable. Then you have to use some workaround. For instance just now. I have config file enumerating multiple files to load: \/\/some header key1=value [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,39,1],"tags":[],"class_list":["post-366","post","type-post","status-publish","format-standard","hentry","category-bash-scripting-unix-sw-computers-unix-sw-computers","category-scripting-unix-sw-computers","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/posts\/366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nax.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=366"}],"version-history":[{"count":0,"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/posts\/366\/revisions"}],"wp:attachment":[{"href":"https:\/\/nax.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nax.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nax.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}