awk

Find all org-mode headings within an org file.

awk '/\*\*/{print}' wiki.org

Find all second-level org-mode headings within an org file.

awk '/^\*\* /{print}' wiki.org

Find all first and secnd-level org-mode headings within an org file by leveraging a logical or statement.

awk '/^\* / || /^\*\* / {print}' wiki.org

Keeping with the theme, find all first, second and third-level org-mode headings within an org file.

awk '/^\* / || /^\*\* / || /^\*\*\* / {print}' wiki.org

This is is the start of a script to chop an org org file into multiple smaller files, nested within sub-directories. The end-goal is to have a page directory for each top-level heading, with 2nd level heading nested within.

# store all 1st, 2nd, and 3rd level headings in a variable
ORG_HEADINGS=$(awk '/^\* / || /^\*\* / || /^\*\*\* / {print}' wiki.org)

# dump them into a temporary text file
echo $ORG_HEADINGS >> all_org_headings.tmp

# FIXME -- replace all spaces between alpha/numeric characters with a dash
awk '{ gsub(/[ ]/,"-"); print }' all_org_headings.tmp

# NAIVE -- replace each top-level heading w/the string "mkdir"
awk '{ gsub(/^\* /, "mkdir "); print }' all_org_headings.tmp

# clean up
rm *.tmp