I have an example of AWK code that I want to export to HTML, both the code and the result of the code. Since AWK codes are usually run in shell with awk 'some awk code' file I use the shell block. The awk block dosn't run the code, it throws a syntax error, presumably it's meant for pure AWK codes?! Not sure. In any case, the shell block colours everything inside quotes as a string in orangish colour. Is there a way to simply switch off the syntax highlighting? Or make the shell block use AWK highlighting? Or make AWK block run commands like awk 'code' file?

  • I found a way to disable the highlighting: (setq org-html-htmlize-output-type nil). Jan 3 '18 at 15:52

You can use AWK block with an input file like this:

#+BEGIN_SRC awk :in-file file.txt :exports results
  {print $4}

Don't forget to add awk to org-babel-do-load-languages

(org-babel-do-load-languages 'org-babel-load-languages '((awk . t)))


 awk -F ";" '{print $4}' test-awk.txt test-awk2.txt

same as

#+BEGIN_SRC awk :in-file test-awk.txt test-awk2.txt :exports results
  BEGIN{FS=OFS=";"} {print $4}
  • I need to show it as an example to be run in terminal as in awk [options] 'code' file1 file2 etc. Jan 3 '18 at 16:10
  • Running an AWK is not the main issue, for pedagogical purposes I need the whole line of code in the export: awk [options] 'code' files. Your code only exports the code itself. But thanks for showing how to make AWK run in the code block, especially the in-file option. Jan 3 '18 at 17:07
  • For awk, you should be able to pass command-line options through the cmd-line header argument: :cmd-line -F ";"
    – NickD
    Jan 3 '18 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.