6d140e6f65c1491b7f6ae406bc4f0acf82cc41d1
kent
  Wed Feb 15 12:07:25 2017 -0800
Making it accept wildcards in field list.

diff --git src/utils/tabQuery/tabQuery.c src/utils/tabQuery/tabQuery.c
index 3899f10..4aed2d0 100644
--- src/utils/tabQuery/tabQuery.c
+++ src/utils/tabQuery/tabQuery.c
@@ -11,31 +11,34 @@
 /* Explain usage and exit. */
 {
 errAbort(
   "tabQuery - Run sql-like query on a tab separated file.\n"
   "usage:\n"
   "   tabQuery rqlStatement\n"
   "where rqlStatement is much like a SQL statement, but with no joins and no commands\n"
   "other than select allowed.  The input file name is taken from the 'from' clause.\n"
   "examples\n"
   "    tabQuery select file,date from manifest.tsv\n"
   "This will output the file and date fields from the manifest.tsv file\n"
   "    tabQuery select file,date,lab from manifest.tsv where lab like 'myLab%%'\n"
   "This will output the selected three fields from the file where the lab starts with myLab\n"
   "    tabQuery select file,data from manifest.tsv where lab='myLab'\n"
   "This will output the selected two fields where the lab field is exactly myLab.\n"
-  "This will output the file and date fields from the manifest.tsv file\n"
+  "    tabQuery select * from manifest.tsv where lab='myLab'\n"
+  "This will output all fields where the lab field is exactly myLab.\n"
+  "    tabQuery select a*,b* from manifest.tsv where lab='myLab'\n"
+  "This will output all fields starting with a or b where the lab field is exactly myLab.\n"
   "    tabQuery select count(*) from manifest.tsv where type='fastq' and size < 1000\n"
   "This will count the number of records where type is fastq and size less than 1000\n"
   );
 }
 
 struct fieldedTable *gTable;
 struct hash *gFieldHash;
 
 char *lookup(void *record, char *key)
 /* Lookup key in record */
 {
 struct fieldedRow *row = record;
 int fieldIx = hashIntValDefault(gFieldHash, key, -1);
 if (fieldIx < 0)
     errAbort("Field %s isn't found in %s", key, gTable->name);
@@ -61,31 +64,44 @@
 
 /* Read in tab separated value file */
 char *tabFile = rql->tableList->name;
 gTable = fieldedTableFromTabFile(tabFile, tabFile, NULL, 0);
 
 /* Make an integer valued hash of field indexes */
 gFieldHash = hashNew(0);
 int i;
 for (i=0; i<gTable->fieldCount; ++i)
     hashAddInt(gFieldHash, gTable->fields[i], i);
 
 /* Make sure all fields in query exist */
 struct slName *field;
 for (field = rql->fieldList; field != NULL; field = field->next)
     if (!hashLookup(gFieldHash, field->name))
+	{
+	if (!anyWild(field->name))
 	    errAbort("field %s doesn't exist in %s", field->name, tabFile);
+	}
+
+/* Make list of fields as opposed to array  */
+struct slName *allFieldList = NULL;
+for (i=0; i<gTable->fieldCount; ++i)
+    slNameAddHead(&allFieldList, gTable->fields[i]);
+slReverse(&allFieldList);
+
+/* Expand any field names with wildcards. */
+rql->fieldList = wildExpandList(allFieldList, rql->fieldList, TRUE);
+
 
 /* Print out label row. */
 if (!doCount)
     {
     printf("#");
     char *sep = "";
     for (field = rql->fieldList; field != NULL; field = field->next)
 	{
 	printf("%s%s", sep, field->name);
 	sep = "\t";
 	}
     printf("\n");
     }
 
 /* Print out or just count selected fields that match query */