An external vendor has provided me a data dump of 20+ tables as *.csv files. Their documentation is lacking so I'm having to manually go through the files to find out which files are 'related' in an RDBMS sense. Is there a way for me to find out which files have same string pattern and neatly print it out?
Currently I'm doing this and manually linking them together:
$> head -n 1 *.csv
This gives me an output like
==> EVO_ANGLE.csv <== "evo_ang_id","angle_description" ==> EVOP_IMAGE.csv <== "evop_image_id","evop_id","evo_ang_id","evo_collection","file_format","image_name","image_path", "image_type" ==> IMAGE_TYPE.csv <== "id","image_type","group","description"
As you can see files
EVOP_IMAGE are related via
IMAGE_TYPE have the
image_type in common.
Is there a better way for me to print this information: Where for each file I can see which other files have the field?
My best crack at this is writing a shell script that does the following in order:
- Get the first line of each file and store in a map in an array
- For each word in each line, find where in array it appears
- Print the output after collating this information.
This is a chore and will require a fair deal of debugging to get right and eyeballing the console output could be faster. Is there a better way? Any tricks with cut/join/grep combo?