MySQL, get (just) column names and write them to a file? - mysql

I would like to get more or less what is discussed in this question.
What more? I would like to redirect the output to a file.
What less? The SHOW columns FROM your-table; actually returns a lot of stuff. In addition to column names it also shows i.e. type.
Ideally, in the end, I would like a plain text file listing one column name per line.

Related

Finding part of a sequence of numerical values in files with unknown name

I have the following problem I would like to solve.
I have a main table file that contains two columns: a unique identifier and a sequence of numerical values. The file looks something like this. The numerical values were copied into this file from a number of different Excel or .csv files (not more than 10). Each of these source files contain a part of the numerical values in the main file. These files look something like this.
I know the approximate, although not the exact length of each of the sub-sequences making up the numerical values in the column in the main file. I do not know the name of the .csv or Excel file where they originally came from.
I would like to do three things:
For each part of the values in the main file, determine which source file they originally came from.
Identify all numerical values that are in the same column but above and below this sub-sequence in the source file.
Copy these numerical values from the column of the sub-sequence in the source file into a new column in the main file.
Save. The results should look like this.
To restate this, the problems are:
I do not know the exact length of each sub-sequence, although I know the approximate length.
I do not know the source file for each sub-sequence of the numerical values in the main file.
In principle, this could be done by hand, but I would rather not. Does someone have an idea how to approach this?

How to get the exact column in Solr search

I am using solr to do product search on a csv. The csv contain multiple columns. Is it possible to get the column name where the solr is getting result from along with the complete row?
my search query: "q=XMC LS"
The CSV looks something like:
Is it possible to get column name "Product" along with the result that is already there?
yes, you can use Highlighting for that. You highlight every field you search on, and then you will get info on what text, and on what field, matched the query. Look at the docs, there are several different highligthers and many params for each of them.

What is the best way to keep track of multiple files (strings) with dynamic properties?

I have a settings file that contains a single string. Only one setting can be set at one time but you can have multiple saved settings. I need to be able to reference the setting by name, category, and subcategory. For example, the category is character and the subcategory is what 2 spells are selected for that character. I want to track them by unique name but also be able to look up a character and spell setting as well.
My current solution is to have a directory with each category and then spell combinations sub folders with the file being stored in the last folder with the title of the setting as the file name. However, my problem is that it's very slow and bulky.
I thought I could store all the information in one file but then I have to search each file when a character is selected. There may not be an additional setting for a particular combination either, which means it just stays whatever it was originally.
In summary, I want to list a string by name or character and each character has a subcategory that has a two string combination. Does anyone have any ideas on the best method to approach this problem?
I also thought about using one file in a Json strong and just deserializing and querying it, but the file could be extremely large. I am working on the program in vb.net.
I can take this down if it's useless. I used one file as a map to the rest of the larger files. The map has the basic metadata as well to prevent me from having to search all the files. I am not sure if it is the best answer but it did work for me. I can take this question down if no one finds this useful.

Searching through a CSV file to know the next macro action

So, I have my current bot (Yes, this bot is entirely legal. It's just a web scraper-esque bot) extracting data from a web page in a loop. But, at the beginning of the loop, I want it to be able to look through the previously-extracted data and compare it to the data on the page to choose what I want to do next. Is this possible?
For example:
Data is saved like this: name1,100,name2,200 Where names can be any string of letters, and the numbers can be any string of numbers.
To give you an idea on what the page looks like: It has two names, each with values under them, and buttons. The names and values change every minute or so.
First, we check the current names on the page. (There are two names on the page)
Next, we compare them to our database to see if they reside in it.
If they both do, we check the numbers after the name
If the first names number is higher than the seconds, we click the first names button
If the second names number is higher than the firsts, we click the second names button
Now we wait twenty seconds
Now, new values have appeared for both names. We find the mean of the new values presented to us and the old values, by adding them together and dividing by two.
What I really need help on is how to search through the CSV file for the names and then numbers after the names, and then how to save data to the same spot as the old data was from.
I know that this is easily possible in most programming languages (Java, C++, etc etc) but I wasn't sure if it would be possible in iMacros.
you can't save data in same csv as you use for search in imacros.
in regular imacros you do not have loop inside loop and IF statements as well, so you need to switch to javascript or similar.
extracting data from csv is simple: http://wiki.imacros.net/!COLn

Insert missing rows in CSV of incrementally numbered files generated by directory listing?

I have created a CSV from a set of files in a directory that are numbered incrementally:
img1_1.jpg, img1_2.jpg ... img1_1999.jpg, img1_2000.jpg
The CSV output is like so:
filename, datetime
eg:
img1_1.JPG,2011-05-11 09:16:33.000000000
img1_3.jpg,2011-05-11 10:10:55.000000000
img1_4.jpg,2011-05-11 10:17:31.000000000
img1_6.jpg,2011-05-11 10:58:37.000000000
The problem is, there are a number of files missing in the listing, as some of the files don't exist. As a result, when imported, the actual row number does not match the file number.
Can anyone think of a reasonably efficient way to insert the missing rows so that the row number and filename matches up other than manually inserting rows for the missing ones? (There are over 800 missing rows).
Background
A previous programmer developed an uploader script and did not save the creation time of the mysql record in the database. I figured the easiest way to find the creation time for the majority of the records would be to output a directory listing of all the files and combine them in a spreadsheet.
You exactly need to do what you write in your comment to answer #tadman.
A text parser script to inject the missing lines with e.g. a date/time value that reflects the record is an empty one, i.e. there is no real data is behind it (e.g. date it to 1950-01-01 00:00:00). When it is done, bulk import the CSV.I think this must be the best and most efficient solution.
Also, think about any future insert/delete/update events might occur to your data.
That would possibly break the chain you initially have had, so you might prefer instead, to introduce a numeric field for the jpegs IDs (and index that field), and leave the PK "as is" (auto increment).
In this case you can avoid CSV manipulation, as well as being chained to your AUTO PK (means: you will not get in trouble if a new jpeg arrives with an ID which was previously deleted, or existing ID, etc).
So the solution really depends on how you want to use this table in the future. If you give more details, I am sure the community can come up with even more ideas.
If it's a one-time thing, it might be easiest to open up your csv in a spreadsheet.
If your table above is in sheet1, you could put something like the following in sheet2 (this is openoffice, but there are similar functions for Excel)
pre_filename | filename | datetime
img1_1 | = A2&".JPG" | =OFFSET(Sheet1.$B$1;MATCH(B2;Sheet1.$A$2:$A$4;0);0)
You should be able to select the three cells above and drag them down to however many you need.