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

  • SEARCH
  • Home
  • 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 7167653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:37:11+00:00 2026-05-28T14:37:11+00:00

Consider a tee export of a MySQL query. SELECT * FROM mytable; +———-+——-+———-+———–+——-+——+——–+ |

  • 0

Consider a tee export of a MySQL query.

SELECT * FROM mytable;
+----------+-------+----------+-----------+-------+------+--------+
| label1   | lbl2  | label3   | label4    | lbl5  | lbl6 | label7 |
+----------+-------+----------+-----------+-------+------+--------+
| ABCDEFGH | YNNYY | 0.001596 |  0.161152 |     2 |    1 | a      |
| ABCDEFGH | YNNYY | 0.001404 |  0.162774 |     3 |    1 | a      |
     *
     *
     *
| ABCDEFGH | YNNYY | 0.001286 | 10.941642 |  5999 |    1 | a      |
| ABCDEFGH | YNNYY | 0.001315 | 10.942950 |  6000 |    1 | a      |
+----------+-------+----------+-----------+-------+------+--------+
9995 rows in set (0.04 sec)

I would like to process this mysqlqtee.txt file through sed or perl, filtering the actual data rows only.

I can tell sed or perl to: “Comment out every line starting with the static text of ‘| AB’, please!”

sed -i '.old' 's/\(^\| AB.*\)/#\1/g' mysqlqtee.txt
perl -pi.old -e 's/(^\| AB.*)/#$1/g' mysqlqtee.txt

These get me:

SELECT * FROM mytable ORDER BY timecode;
+----------+-------+----------+-----------+-------+------+--------+
| label1   | lbl2  | label3   | label4    | lbl5  | lbl6 | label7 |
+----------+-------+----------+-----------+-------+------+--------+
#| ABCDEFGH | YNNYY | 0.001596 |  0.161152 |     2 |    1 | a      |
#| ABCDEFGH | YNNYY | 0.001404 |  0.162774 |     3 |    1 | a      |
     *
     *
     *
#| ABCDEFGH | YNNYY | 0.001286 | 10.941642 |  5999 |    1 | a      |
#| ABCDEFGH | YNNYY | 0.001315 | 10.942950 |  6000 |    1 | a      |
+----------+-------+----------+-----------+-------+------+--------+
9995 rows in set (0.04 sec)

nicely commenting out all the actual data rows and leave every other line untouched.

What I am so far unable to tell perl or sed is to: “Comment out every line starting with anything OTHER THAN the static text of ‘| AB’, please!”
Which would get me:

#SELECT * FROM mytable ORDER BY timecode;
#+----------+-------+----------+-----------+-------+------+--------+
#| label1   | lbl2  | label3   | label4    | lbl5  | lbl6 | label7 |
#+----------+-------+----------+-----------+-------+------+--------+
| ABCDEFGH | YNNYY | 0.001596 |  0.161152 |     2 |    1 | a      |
| ABCDEFGH | YNNYY | 0.001404 |  0.162774 |     3 |    1 | a      |
     *
     *
     *
| ABCDEFGH | YNNYY | 0.001286 | 10.941642 |  5999 |    1 | a      |
| ABCDEFGH | YNNYY | 0.001315 | 10.942950 |  6000 |    1 | a      |
#+----------+-------+----------+-----------+-------+------+--------+
#9995 rows in set (0.04 sec)

I don’t seem to be able to translate the “IT DOESN’T START WITH” part to regexp.
The dual use of ^ meaning NOT and LINE_START at the same time causes trouble.
I can negate the starting letter with s/^[^\|]/, but that also leaves the header row out.

I managed to do this in perl, using an IF statement.
But it still disturbs me way too much that I couldn’t do it with a single s///g.
Can this be done that way?

How do I translate the “IT DOESN’T START WITH” part to regexp? Either sed or perl solution is fine!

  • 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-05-28T14:37:12+00:00Added an answer on May 28, 2026 at 2:37 pm

    You can negate a regex with sed by putting ! after it like so:

    sed -i.old '/^| AB/!s/^/#/' mysqltree.txt
    

    Output

    $ sed '/^| AB/!s/^/#/' mysqltree.txt
    #SELECT * FROM mytable;
    #+----------+-------+----------+-----------+-------+------+--------+
    #| label1   | lbl2  | label3   | label4    | lbl5  | lbl6 | label7 |
    #+----------+-------+----------+-----------+-------+------+--------+
    | ABCDEFGH | YNNYY | 0.001596 |  0.161152 |     2 |    1 | a      |
    | ABCDEFGH | YNNYY | 0.001404 |  0.162774 |     3 |    1 | a      |
    | ABCDEFGH | YNNYY | 0.001286 | 10.941642 |  5999 |    1 | a      |
    | ABCDEFGH | YNNYY | 0.001315 | 10.942950 |  6000 |    1 | a      |
    #+----------+-------+----------+-----------+-------+------+--------+
    #9995 rows in set (0.04 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following 2 queries: select tblA.a,tblA.b,tblA.c,tblA.d from tblA where tblA.a not in (select
Consider an indexed MySQL table with 7 columns, being constantly queried and written to.
Consider 3 regex expressions designed to remove non Latin characters from the string. String
Consider the following example quoted from php manual for DateTime <?php $date = new
Consider this: Requisite: //The alphabet from a-z List<char> letterRange = Enumerable.Range('a', 'z' - 'a'
Consider this url: www.anysite.com/get_count/?sex=5&sex=6&city=5&city=7&job=7&job=8...... For using in dynamic query in view: model = anyModel.objects.filter(sex=5).filter(sex=6).filter(city=5)....
Consider this title for a web page: This is a mixed text from right-to-left
Consider the following setup: A windows PC with a LAN interface and a WiFi
Consider the need to develop a lightweight desktop DB application on the Microsoft platforms.
Consider: List<String> someList = new ArrayList<>(); // add "monkey", "donkey", "skeleton key" to someList

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.