.oO  |  List directory  |  History  |  Similar  |  Print version
Home 
Main 
   Databases 
   qmail 
   Old Braindump Pages 
Linux 
FreeBSD 

Main > split a file with awk

 
rw-rw-r--   ian   linux

split a file with 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


Reference http://braindump.mrzesty.net/Main/SplitAFileWithAwk

Comments: 0 New comment

Prev. opsview   SSLv3 disable weak Ciphers Next


Home | Main | Linux | FreeBSD