{"id":1578,"date":"2020-04-12T08:49:27","date_gmt":"2020-04-12T13:49:27","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1578"},"modified":"2020-04-12T11:54:05","modified_gmt":"2020-04-12T16:54:05","slug":"bash-scan-text-block-reverse","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/bash-scan-text-block-reverse\/","title":{"rendered":"bash-scan-text-block-reverse"},"content":{"rendered":"

example finding a block.<\/h1>\n

start string and reverse search up to next string. then replacing a line inside the block<\/p>\n

bash example<\/h3>\n
$ cat listener-update.sh \n#!\/bin\/bash\n#v0.9.1\nfile="listener_test.yml"\ndir=".\/unregister"\nvariable="bar"\n\ncodeuri_num=$(grep -n "CodeUri: $dir" $file | awk '{print $1}' FS=":")\nfunction_num=$(grep -n "Type: 'AWS::Serverless::Function'" $file | awk '{print $1}' FS=":")\nblock=$(sed "${function_num},${codeuri_num}!d" $file)\n\necho\nif [[ "$block" == *"AutoPublishCodeSha256"* ]];then\n  echo "found AutoPublishCodeSha256 so update"\n  line=$(echo "${block}" | grep -n "AutoPublishCodeSha256")\n  line_num=$(awk "\/Auto\/ && NR >= ${function_num} && NR <= ${codeuri_num} {print NR}" $file)\n  newline="AutoPublishCodeSha256: $var"\n  sed -i "${line_num}s\/.*\/ \\ \\ \\ \\ \\ AutoPublishCodeSha256: $variable\/" $file\nelse\n  echo "AutoPublishCodeSha256 not found so insert"\n  #codeuri_num=$((codeuri_num+1))\n  sed -i "${codeuri_num} i \\ \\ \\ \\ \\ \\ AutoPublishCodeSha256: $variable" $file\nfi<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

example finding a block. start string and reverse search up to next string. then replacing a line inside the block<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1578","post","type-post","status-publish","format-standard","hentry","category-bash"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1578"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1578\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}