From: Eric Schulte Date: Mon, 7 Jan 2013 18:22:11 +0000 (-0700) Subject: txt2org convert text data to org-mode tables X-Git-Tag: release_7.9.3~1^2 X-Git-Url: http://orgmode.org/w/?p=worg.git;a=commitdiff_plain;h=7679c02536a4e991d1b74092c8462ca3971a8c1c txt2org convert text data to org-mode tables --- diff --git a/org-hacks.org b/org-hacks.org index b10b4d7..48fe0a6 100644 --- a/org-hacks.org +++ b/org-hacks.org @@ -2878,6 +2878,85 @@ popup window. Richard Riley uses gnome-osd in interaction with Org-Mode to display appointments. You can look at the code on the [[http://www.emacswiki.org/emacs-en/OrgMode-OSD][emacswiki]]. +** txt2org convert text data to org-mode tables +From Eric Schulte + +I often find it useful to generate Org-mode tables on the command line +from tab-separated data. The following awk script makes this easy to +do. Text data is read from STDIN on a pipe and any command line +arguments are interpreted as rows at which to insert hlines. + +Here are two usage examples. +1. running the following + : $ cat < max_nf){ max_nf = NF; }; + for(f=1; f<=NF; f++){ + if(length($f) > lengths[f]){ lengths[f] = length($f); }; + row[NR][f]=$f; } } + + END { + hline_str="|" + for(f=1; f<=max_nf; f++){ + for(i=0; i<(lengths[f] + 2); i++){ hline_str=hline_str "-"; } + if( f != max_nf){ hline_str=hline_str "+"; } + else { hline_str=hline_str "|"; } } + + for(r=1; r<=NR; r++){ # rows + if(hlines[r] == 1){ print hline_str; } + printf "|"; + for(f=1; f<=max_nf; f++){ # columns + cell=row[r][f]; padding="" + for(i=0; i<(lengths[f] - length(cell)); i++){ padding=padding " "; } + # for now just print everything right-aligned + # if(cell ~ /[0-9.]/){ printf " %s%s |", cell, padding; } + # else{ printf " %s%s |", padding, cell; } + printf " %s%s |", padding, cell; } + printf "\n"; } + + if(hlines[NR+1]){ print hline_str; } } +#+end_src + ** remind2org #+index: Agenda!Views #+index: Agenda!and Remind (external program)