Created
September 30, 2010 19:36
-
-
Save roder/605174 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This utility is useful for extracting the field names from a SQL to CSV export | |
# | |
# csvheadpivot will scan the current working directory for CSV files. When it | |
# encounters a CSV file the utility assumes the CSV file has a header row and | |
# any CSV files with more than one row has data. | |
# | |
# When encountering a CSV with data, the utility will grab the header row and | |
# pivot it to a single column. | |
mkdir ./fields; | |
echo "Created fields directory in the current working directory." | |
echo "Searching current working directory for CSV" | |
echo "Creating fields file in ./fields/:" | |
for i in `ls *.csv`; | |
do res=`wc -l $i`; | |
lc=`echo $res | cut -d ' ' -f 1`; | |
if [ $lc -gt 1 ]; | |
then | |
head -1 $i | sed 's:,:\ | |
:g' > ./fields/fields-$i; | |
echo " fields-$i"; | |
fi | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment