Skip to content

Instantly share code, notes, and snippets.

@bradymholt
Created March 6, 2015 01:44
Show Gist options
  • Save bradymholt/d140727a0e588d8e445e to your computer and use it in GitHub Desktop.
Save bradymholt/d140727a0e588d8e445e to your computer and use it in GitHub Desktop.
Concatenates multiple .sql files into single .sql. Written for SQL Server Management Studio .sql files which are encoded using UCS-2LE.
#!/bin/bash
rm $2
files="${1}"
temp_file="tmp_combine"
temp_file_2="tmp_combine_2"
for file in $files; do
echo "${file}"
iconv -f "UCS-2LE" -t "UTF-8" "${file}" >> $temp_file
echo "" >> $temp_file
echo "GO" >> $temp_file
echo "" >> $temp_file
done
perl -p -e 's/(?<!\r)\n/\r\n/' < $temp_file > $temp_file_2
iconv -f "UTF-8" -t "UCS-2LE" $temp_file_2 >> $2
rm $temp_file
rm $temp_file_2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment