lainchan / λ

vaersi(1) VAERS Interactive v1.6.3

Meddler · 2022-01-25 05:46
Good day. I haven't programmed in a long while, and I hope to pick it up again soon now that I have the time and the ability. I haven't programmed in a good while and have been a bit rusty. I plan to retake the C Programming Language which I started K&R C for several years ago but never finished. I've seen some of SCIP's video lecture series, but haven't gone through the book. I am well versed in UNIX systems and the shell more than anything. It has also been a while since I have shell-scripted. I desiged to attempt to make this program to automate what I was doing in a few commands, and now I want to share it to see what others think about it. It is just barebones right now. It is in POSIX but still has some minor bashisms. It seems to run right. I also believe that this is perhaps an important tool to share and distribute once I polish it up, and add a few more features. I think that I may remake the program in C as a learning experience. Please bugtest my code and tell me how I can get better, please. ############################################################################# # vaersi(1) VAERS Interactive # Interactively sort VAERS data by lot number # # $Id vaersi,v 1.6.3 2022/01/25 05:05:06 se7en Exp se7en $ # # KoppiMi and CC0 (Public Domain) by se7en <botbegone@noemail.invalid> # # This script is designed to be an interactive tool to search for a Covid-19 # Lot Number in the VAERS Reporting Database. The script also functions for # other Lot Numbers. # # TODO: fix up keyword search for regex, remove remaining Bashisms for # full-POSIX, conform to style-guide and best practices, make rendering more # pretty
Drifter · 2022-01-25 06:13
cool. I have no use for this.
Tank · 2022-01-25 06:39
>>29622 I forgot to provide a valid sample number, 037K20A
Meddler · 2022-01-25 08:04
I made a small update to the script.
Stallman · 2022-01-25 11:29
>>29622 v 1.6.6. Cleaned up the code mostly.
array · 2022-01-25 12:27
1. Run shellcheck. 2. set -eu (or use #!/bin/sh -eu) at the top. 3. Use getopts instead of your menu contraption. 4. Don't exit with status != 0 when the user voluntarily quits. 5. In the last part, avoid searching twice by storing the search result in a variable then testing it for emptyness and refactor that whole block that essentially states 3 time the same soykaf with different inputs (which is what functions are for). 6. Your PAGER variable is useless, as it assumes options that are clearly specific to less (which isn't POSIX; more is). You better unquote $PAGER so that people can actually specify a pager with additional options. 7. grep -w, column, unzip aren't POSIX. 8. Use -- to avoid user input being interpreted as options instead of arguments. In general, your code looks like old timer visual basic/pascal. Use an actually "good" scripting language (Python, Lisp, Tcl), as you'll probably never get good enough to master sh and avoid its pitfalls; and if you do, you'll switch anyway when not needing maximum portability because you'll realize POSIX sh + env is neutered.
cdr · 2022-01-25 22:26
>>29629 >>29629 I have taken a lot of your notes here. Running shellcheck presented only style concerns regarding my checking of grep, and when I had attempted to change the script to better style it completely broke. shellcheck even said it had nothing to report. You are right, column is a BSD project, not standard UNIX so I am trying to create an awk function in the script called `table`, which I will take stdin from `pr -s t`. This should make it more universal. This is what I am currently stuck on. I have changed $PAGER, but note that less has been commonly adopted since 1984 on nearly all UNIXes, but you are right it would be better to program for more. I do not know how to emulate less's linesplitting in more. I have changed exit to 0, rather than 1. That was a simple overlooked mistake. I have changed grep -w to grep -F (I haven't tested this yet), as well as made a checker for the unzip utility. If unzip is not found, a download link to Info-Zip (standard version of the utility) is presented. I am working on making the keyword search a function. I am not sure how to use getopts, but I am looking into it. >8. Use -- to avoid user input being interpreted as options instead of arguments. Do you mean in my read arguments? These are the only inputs. I found awk code but I am unsure how to implement it. This is from Stack Exchange. It was originally presented as a stand-alone awk script and I am unsure how to properly put this into the code. # Make pr like BSD Column table () { env awk { if (max_column < NF) max_column = NF; for (i = 1; i <= NF; i++) { if (width[i] < length($i)) width[i] = length($i); data[NR, i] = $i; } } END { for (i = 1; i < max_column; i++) format[i] = sprintf("%%-%ds ", width[i]); format[max_column] = "%s\n"; for (k = 1; k <= NR; k++) { for (i = 1; i <= max_column; i++) printf format[i], data[k, i]; } } } A simpiler version was also provided, but as it is hardcoded to three csv values, I don't think it's too good. [code] awk '{printf("%2s %30s %10s", $1, $2, $3);}' file.txt To your point of using an "actual" programming language, I will. Once I am happy with this, I am going to remake the program in C as a first excersise.
Nobody special · 2022-01-25 22:34
>>29633 I apoligize for that sloppyness. Here is the awk program that Stack Exchange made, in my broken function in the script: table() { env awk { if (max_column < NF) max_column = NF; for (i = 1; i <= NF; i++) { if (width[i] < length($i)) width[i] = length($i); data[NR, i] = $i; } END { for (i = 1; i < max_column; i++) format[i] = sprintf("%%-%ds ", width[i]); format[max_column] = "%s\n"; for (k = 1; k <= NR; k++) { for (i = 1; i <= max_column; i++) printf format[i], data[k, i]; } } And the simpiler awk string. awk '{printf("%2s %30s %10s", $1, $2, $3);}' file.txt I know Lainchan isn't as active as other places, so there's a good chance I'll figure this out before someone replies
Delilah · 2022-01-25 23:04
>>29634 I decided to skip that for now, and move back to the issue of getopts. Researching this, it appears that getopts is reliable and in POSIX, but getopt is an older method of using an external utility. I have chosen to use getopts. However, the script closes at my implementation. The (((Modern Web))) is terrible for this, and using a web search I continue to find incredibly irrelevant information. Wikipedia had code-snippits of GetOpts. Some were more complex than others. From what I read it appears that I have implented it correctly. It crashes the script nonetheless. while printf " To view select option: 1) Look through complete dataset for %s 2) Look through known symptoms for %s 3) Look through BOTH 4) Grep by State 5) Grep by Keyword q) Quit Choose Option [1-5 or Quit]: " "$number" "$number" >&2 getopts ':1:2:3:4:5:q' selection1; do printf "" case $selection1 in 1) column -s, -t < "$DATANUMBER" | less -#1 -N -S ;; ...
Anonymous · 2022-01-25 23:32
>>29634 I downloaded the POSIX manpages (which were in Debian's non-free). I read the manpage for getopts(1POSIX) and it shows only one example aflag= bflag= while getopts ab: name do case $name in a) aflag=1;; b) bflag=1 bval="$OPTARG";; ?) printf "Usage: %s: [-a] [-b value] args\n" $0 exit 2;; esac done if [ ! -z "$aflag" ]; then printf "Option -a specified\n" fi if [ ! -z "$bflag" ]; then printf 'Option -b "%s" specified\n' "$bval" fi shift $(($OPTIND - 1)) printf "Remaining arguments are: %s\n$*" This produces input back into output. However, I thought that it was interesting that ab is not :a:b. I changed my own code sample to getopts '12345q:' selection1; do This still causes a fault.
Y.T · 2022-01-26 02:34
Well, new release #!/bin/sh -eu ############################################################################# # vaersi(1) VAERS Interactive # Interactively sort VAERS data by lot number # # $Id vaersi,v 1.7.0 2022/01/26 02:00:40 AM se7en Exp se7en $ # # KoppiMi and CC0 (Public Domain) by se7en <se7en@cock.email> # # This script is designed to be an interactive tool to search for a Covid-19 # Lot Number in the VAERS Reporting Database. The script also functions for # other Lot Numbers. # # TODO: Make more universal by making more POSIX-compliant. The commands # column(1), less(1) are not POSIX. less(1) is an independent pager made # commonplace in 1987. column(1) is a BSD utility that has carried-over # into util-linux. In order to use the equivelent of the features called, # I would need to make advanced awk(1) commands that would influence the # POSIX-standard commands pr(1) and more(1). I assume this is actually # possible because csv-like standard data has existed since 1972. # # TODO: add non-interactive mode for basic terminal input. Means I also # need to remove Hardcoding of specific files. This will require rewriting # of my menu, replacing it with getopts which will define input outside # of the interactive session (e.g. `vaersi 12345D -1` for viewing full # dataset. This will also be well for year-independent parsing of data. # # TODO: add feature that is year-independent, allowing for user-input # to specify # # TODO: Cleanup basic style. Conform to best practices. # # Known Bug: Running grep for state brings back others as POSIX-compatible # grep(1) does not have option -w. Possible workaround in sed(1)??? # # Known Bug: output of parsed symptomfile is terrible because every report # is a single line. Spacing is also bad for symptomfile.
Ishikura "Tatsu" Tatsuhiko · 2022-01-26 09:25
>>29633 I made one some time ago: https://git.sr.ht/~q3cpma/scripts/tree/master/item/tabulate.sh#L64 Be aware, it's very complete, thus quite bigger than what you may expect.
Mario Rossi · 2022-01-26 10:03
>>29639 Thank you. I have now made a git repo for it, because that's better. I've also changed the license declaration to GPLv3 going forward because yes. https://gitgud.io/se7en_gitgud/vaersi
Debbie Charteris · 2022-01-27 08:27
>>29643 >>29643 >>29649