User Tools

Site Tools


Split a File Using Awk

I needed to split a large file (in this case a mysql dump of all databases combined) into individual files each consisting of the SQL statements related to that DB. [Remember COBOL batch processing?]

Each section of the mysql database starts with:

-- Current Database: `mysql`
awk -F'`' '{if ($0 ~ /^-- Current Database:/) db=$2; print >> db"-20110301.sql"}' mysql-full-Tuesday.sql
splitafilewithawk.txt · Last modified: 2020/02/13 22:55 (external edit)

free spam filter