Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8467097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:32:36+00:00 2026-06-10T15:32:36+00:00

I have what I thought was a simple problem. I have a mysqldump file

  • 0

I have what I thought was a simple problem. I have a mysqldump file occupying several GBs, and I want to create a script that will extract just the lines of the text pertaining to one table (variable passed to the script) and save those to a new file.

The section I want to extract always starts with:

-- Table structure for table `myTable`

And always ends with:

UNLOCK TABLES;

Where the table name and the number of lines I want afterward are variable. I’m able to find the start of the section with:

START=$(grep -n "Table structure for table \`$2\`" "$1" | awk -F ":" '{print $1}')

Where $1 is the file to search and $2 is the table name. This works just fine, but then I’m stuck. I know I can extract the lines with sed once I have the ending line number, but finding that ending line number is the tricky part.

I need to find the line number of the first occurrence of UNLOCK TABLES; after my $START line number, and I’m lost on how to do that.

For more detail, here’s an example of one section of text I would want to extract:

--
-- Table structure for table `myTable`
--

DROP TABLE IF EXISTS `myTable`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `myTable` (
  `column1` varchar(12) NOT NULL,
  `column2` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`column1`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `myTable`
--

LOCK TABLES `myTable` WRITE;
/*!40000 ALTER TABLE `myTable` DISABLE KEYS */;
INSERT INTO `myTable` VALUES ('test11', 'test12'),('test21', 'test22');
/*!40000 ALTER TABLE `myTable` ENABLE KEYS */;
UNLOCK TABLES;

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:32:38+00:00Added an answer on June 10, 2026 at 3:32 pm

    Use sed; you don’t need to worry about explicit line numbers; you can just select the range using regexes for both the first and last line.

    firstLine="-- Table structure for table \`$2\`"
    secondLine="UNLOCK TABLES;"
    
    sed -n "/$firstLine/,/$secondLine/p" "$1"
    

    The -n limits sed to printing only those lines that match the desired range.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following problem. I want to create a file system based session storage
I'm trying to create a simple Automator workflow that will prompt me for where
simple example of the problem: i have an app that can download backgrounds from
I have a User model that has a :credits attribute. I want a simple
I would have thought this one would be simple but I'm trying to change
I would have thought that this would be an easy thing to do, but
In short, when you have planned or have thought about an idea to create
I came across this code on reddit . I would have thought that type
I have always thought that in order to connect to SQL server using windows
What I thought was going to be a simple problem turns out to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.