(Disclaimer: I know this may seem like a very specific question. But: I haven't found the answers to similar questions to be close enough to what I need. I hope to get an answer that is easily understood, and that people can adapt to their own needs, without having learned elisp)
I have an already existing table, that I want to append rows to with org-capture
The workflow I want:
Shortcut pressed
Menu pops up asking "Should this be an internal link?". Answer with y/n
If yes, the name-field in pt. 3 should be this:
[[#PLACEHOLDER-NN] [Name]]
PLACEHOLDER is just the text "PLACEHOLDER". I'll fill that in later
- is an actual hyphen
NN is the next custom-ID-number. I use the "name hyphen incremented_number"-format to avoid having identical custom IDs
- Right now, I use a one-liner to find the highest number used so far. Shown at the end of the post.
Space between to prevent emacs from smooshing the link together, so that I can see which PLACEHOLDERs need replacing. I'll remove the space by hand after replacing the PLACEHOLDER.
- Name is the name of the project
Else: The name-column is just text entered by me
Press enter
Get to the next column, titled "2 Comment"
Enter Comment-content. Might be empty. Hit enter to skip
Hit enter when finished entering comment
Get to "3 Tags"-column
Enter tags
Hit enter to get to next column. Skipping column #4
Enter contents into 6 more columns
When that's done, perform the calculation (#+TBLFM: $4=($5+$6+$7+$8-$9-$10)) right underneath the table
Table is resorted by column titled "4 Total". Header- and separator-row stay where they are
Answer to similar thread: Org capture into org table - I don't know enough elisp to modify it to my needs
Possibly complicating factors:
My table isn't right under a top-level heading. There's a top-level heading, some text, a blank line, and then the table
I have that calculation right underneath the table
One-liner:
grep ^\ *:CUSTOM_ID: ~/Path/To/file.org | awk '{print $2}' | awk -F '-' '{print $2}' | sort -n | tail -1
Searches for lines that start with 0 or more spaces, then have the phrase ":CUSTOM_ID:", as in the start of an internal link. The next argument specifies which file it searches through. Then awk first displays only the 2nd field (the custom ID itself. We're not interested in the phrase ":CUSTOM_ID:"). Then awk uses a hyphen as a separator, and prints only the 2nd field there: the numbers after the hyphens. Now that we have these numbers, we can numerically sort by them, and use tail -1 to display just the last (and largest) of these numbers. The next number should be largest-number + 1