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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:40:38+00:00 2026-05-23T08:40:38+00:00

I have a line in my.cnf file datadir = /var/lib/mysql The following changes it

  • 0

I have a line in my.cnf file

datadir = /var/lib/mysql

The following changes it to mysql3307 as expected.

sed -i 's/\/var\/lib\/mysql$/\/var\/lib\/mysql3307/' /etc/my.cnf

But if I have the following:

datadir = /var/lib/mysql/

Then the following does not change the path as expected:

sed -i 's/\/var\/lib\/mysql\/$/\/var\/lib\/mysql3307/' /etc/my.cnf

I want to change the path to mysql3307 where datadir is /var/lib/mysql (with or without /)

Update:

Here is the issue:
Both the above commands works on one server and none of them works on another.

The following works as expected, but I need to add that $ to indicate the lines ending with mysql/

sed -i 's/\/var\/lib\/mysql\//\/var\/lib\/mysql3307/' /etc/my.cnf

Observed:

The carot sign ^ works as expected, but end of line sign $ does not. Any clue?

Update:

It seems to be working after using “dos2unix” command.

  • 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-23T08:40:38+00:00Added an answer on May 23, 2026 at 8:40 am

    If your intent is to only change paths that have that specific directory, you need to be a bit trickier. You have to catch it at the end of a line without the trailing / and you also have to catch it everywhere it has the trailing / (end of line or not).

    But you don’t want to catch things like /var/lib/mysqlplus since that’s a totally different directory.

    Consider using extended regular expressions, and using a different separator character so you command doesn’t look like sawteeth (/\/\/\/\/\/\/\/\). With those changes, and a small modification to the regular expression itself, it works fine:

    $ echo '
    /var/lib/mysqlplus
    /var/lib/mysql/
    /var/lib/mysql
    /var/lib/mysql/xyz' | sed -E 's|/var/lib/mysql([$/])|/var/lib/mysql3307\1|'
    
    /var/lib/mysqlplus
    /var/lib/mysql3307/
    /var/lib/mysql
    /var/lib/mysql3307/xyz
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the file.txt I have line with quotes as the following D:\file.txt: \\server1\pc1\targetG0\source-pc\pkgs.gz My
I have line: imagejpeg($this->image, $file, $quality); How can add on this image watermark.png?
I currently have a huge HTML file which doesn't have line breaks and just
I'm reading a file using bufferedreader, so lets say i have line = br.readLine();
I have one line in php file like this: <a class=hide-if-no-js onclick=findPosts.open( 'media[]','<?php echo
I have images which have line segments, rays etc. I am representing these line
My columns have line breaks, but how can I convert these to vbCrLf when
Is it possible to have line breaks in an ini file using Delphi? I
I can't seem to find the my.cnf or other config file for the MySQL
i like to have line numbers ON in Vim but sometimes line numbers are

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.