List:General Discussion« Previous MessageNext Message »
From:Prabhat Kumar Date:November 14 2011 3:41pm
Subject:Re: parsing a .sql file
View as plain text  
You can extract table names and all the fields use linux command *SED*.
http://www.cyberciti.biz/faq/sed-display-text/

sometime I used sed command to extract single database from multiple
databases dump file.

using sed to extract single database from the dumpfile:
=========================================
sed -n '/^-- Current Database: `dbname`/,/^-- Current Database: `/p'
dumpfile > dbname.sql 2>error

Thanks,



On Sun, Nov 13, 2011 at 1:08 PM, Fahim Mohammad <fahim.md@stripped> wrote:

> I have the following info in a text file called  file.sql
> Is there a way to extract table name and all the fields in this table.
>
> Thanks.
>
> Fahim
>
>
> -- MySQL dump 10.11
> --
> -- Host: localhost    Database: ailMel1
> -- ------------------------------------------------------
> -- Server version 5.0.67
>
> /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
> /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
> /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
> /*!40101 SET NAMES utf8 */;
> /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
> /*!40103 SET TIME_ZONE='+00:00' */;
> /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='' */;
> /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
>
> --
> -- Table structure for table `all_est`
> --
>
> DROP TABLE IF EXISTS `all_est`;
> SET @saved_cs_client     = @@character_set_client;
> SET character_set_client = utf8;
> CREATE TABLE `all_est` (
>  `bin` smallint(5) unsigned NOT NULL,
>  `matches` int(10) unsigned NOT NULL,
>  `misMatches` int(10) unsigned NOT NULL,
>  `repMatches` int(10) unsigned NOT NULL,
>  `nCount` int(10) unsigned NOT NULL,
>  `qNumInsert` int(10) unsigned NOT NULL,
>  `qBaseInsert` int(10) unsigned NOT NULL,
>  `tNumInsert` int(10) unsigned NOT NULL,
>  `tBaseInsert` int(10) unsigned NOT NULL,
>  `strand` char(2) NOT NULL,
>  `qName` varchar(255) NOT NULL,
>  `qSize` int(10) unsigned NOT NULL,
>  `qStart` int(10) unsigned NOT NULL,
>  `qEnd` int(10) unsigned NOT NULL,
>  `tName` varchar(255) NOT NULL,
>  `tSize` int(10) unsigned NOT NULL,
>  `tStart` int(10) unsigned NOT NULL,
>  `tEnd` int(10) unsigned NOT NULL,
>  `blockCount` int(10) unsigned NOT NULL,
>  `blockSizes` longblob NOT NULL,
>  `qStarts` longblob NOT NULL,
>  `tStarts` longblob NOT NULL,
>  KEY `tName` (`tName`(8),`bin`),
>  KEY `qName` (`qName`(12))
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
> SET character_set_client = @saved_cs_client;
>
> /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
>
> /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
> /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
> /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
> /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
> /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
>
> -- Dump completed on 2011-04-18  4:14:26
>



-- 
Best Regards,

Prabhat Kumar
MySQL DBA

My Blog: http://adminlinux.blogspot.com
My LinkedIn: http://www.linkedin.com/in/profileprabhat

Thread
parsing a .sql fileFahim Mohammad13 Nov
  • Re: parsing a .sql filePrabhat Kumar14 Nov