dbfc0218144b3b00f7ab1869478239535f6597ae kent Tue Apr 17 17:50:59 2012 -0700 A handy little text utility, sort of a text PCR. diff --git src/utils/textBetween/textBetween.c src/utils/textBetween/textBetween.c new file mode 100644 index 0000000..9575cb2 --- /dev/null +++ src/utils/textBetween/textBetween.c @@ -0,0 +1,54 @@ +/* textBetween - Print all text in file between two input strings.. */ +#include "common.h" +#include "linefile.h" +#include "hash.h" +#include "options.h" +#include "obscure.h" + +/* Command line variables. */ +boolean withEnds; + +void usage() +/* Explain usage and exit. */ +{ +errAbort( + "textBetween - Print all text in file between two input strings including the strings.\n" + "usage:\n" + " textBetween before after fileName\n" + "options:\n" + " -withEnds - If set include the before and after strings in the output\n" + " -xxx=XXX\n" + ); +} + +static struct optionSpec options[] = { + {"withEnds", OPTION_BOOLEAN}, + {NULL, 0}, +}; + +void textBetween(char *before, char *after, char *fileName) +/* textBetween - Print all text in file between two input strings.. */ +{ +char *gulp; +size_t gulpSize; +readInGulp(fileName, &gulp, &gulpSize); +char *s = stringBetween(before, after, gulp); +if (s == NULL) + errAbort("Couldn't find anything"); +if (withEnds) + fputs(before, stdout); +fputs(s, stdout); +if (withEnds) + fputs(after, stdout); +} + +int main(int argc, char *argv[]) +/* Process command line. */ +{ +optionInit(&argc, argv, options); +withEnds = optionExists("withEnds"); +if (argc != 4) + usage(); +textBetween(argv[1], argv[2], argv[3]); +return 0; +}