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 9217157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:34:46+00:00 2026-06-18T02:34:46+00:00

I have a file: $ cat dd.txt *************************** 1. row *************************** File: log-bin.00005 Position:

  • 0

I have a file:

$ cat dd.txt
*************************** 1. row ***************************
            File: log-bin.00005
        Position: 120614936
    Binlog_Do_DB:
Binlog_Ignore_DB:

I want only these values from above file log-bin.000055, 120614936

Now I want to update file,position in my slave table.

update db.position set binlog_file='log-bin.000055',position='120614936' where master_host='master.tb.com';

How do I write a simple script for it?

  • 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-18T02:34:47+00:00Added an answer on June 18, 2026 at 2:34 am

    Using GNU Grep and positive lookbehind:

    $ grep -Po "(?<=File: )[^ ]+|(?<=Position: )[0-9]+" dd.txt
    log-bin.00005
    120614936
    
    # Store file in variable 
    $ file=$(grep -Po "(?<=File: )[^ ]+" dd.txt)
    
    # Store position in variable
    $ pos=$(grep -Po "(?<=Position: )[0-9]+" dd.txt)
    
    # Generate query using variable and store in variable
    $ query="update db.position set binlog_file='"$file"',position='$pos' where master_host='master.tb.com';"
    
    $ echo $query    
    
    update db.position set binlog_file='log-bin.00005',position='120614936' where master_host='master.tb.com';
    
    # Pipe query to mysql
    $ echo $query | mysql -u user -ppassword 
    

    As a script:

    #!/bin/bash
    
    file=$(grep -Po "(?<=File: )[^ ]+" dd.txt)
    pos=$(grep -Po "(?<=Position: )[0-9]+" dd.txt)
    
    $ query="update db.position set binlog_file='"$file"',position='$pos' where master_host='master.tb.com';"
    $ echo $query | mysql -u user -ppassword 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file test.txt with content like below: $ cat test.txt IA/N1143 1
I have a text file, a.txt. Contents are: $ cat a.txt microsoft.com google.com ibm.com
I have this test file. [root@localhost ~]# cat f.txt a aa MM bbb b
I have a file that look like this: > cat my.txt This is sentence
I have a simple file called dbs.txt I want to echo the lines of
Say I have this file: cat > test.txt <<EOF line one word line two
I have a file a.txt . cat a.txt > hello The contents of a.txt
I have a file with the following lines in it: bash$ cat blah.txt <smsDeliveryStatus
I have a txt file with 3 lines. User$ cat file.txt 5 - an
I have many words [MM] in a file. I ran this command: cat file.txt

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.