Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 12-14-2017, 03:09 PM   #1
LQ Newbie
Registered: Jan 2016
Posts: 6

Rep: Reputation: Disabled
replace a character in lvm.conf

Hi All,

Looks like redhat made an update to /etc/lvm/lvm.conf.
They had a units = h paramater that now reads units = r
this is causing us an issue.
My question is: I need to scan thru the file and see if it has a units = r parameter, and if not found exit. if found change the value to units = h.
I can grep for the value: grep units /etc/lvm/lvm.conf |grep -v "#" - which will return the value. but my experience with if / then and sed are limited.


Old 12-15-2017, 12:43 PM   #2
Ser Olmy
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 2,485

Rep: Reputation: Disabled
You could try:
sed -i 's/units = r/units = h/' /etc/lvm/lvm.conf
The "-i" parameter makes sed perform in-place editing of a file.
Old 12-15-2017, 03:45 PM   #3
Registered: Dec 2011
Location: Simplicity
Posts: 653

Rep: Reputation: 299Reputation: 299Reputation: 299
A bit more sophisticated: skip comments, only change the file if necessary, and leave a backup.
wrong='^([[:blank:]]*units *= *"?)r("?) *$'
if egrep -q "$wrong" "$file"
  echo "replacing units=r with units=h, backup $orig"
  if cp -p "$file" "$orig"
    sed -r "s/$wrong/\1h\2/" < "$orig" > "$file" || cp -p "$orig" "$file"

Last edited by MadeInGermany; 12-15-2017 at 03:47 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace character in between?? gedit?? Drigo Linux - Newbie 7 04-04-2013 06:37 PM
Replace second character instead of first Drigo Linux - Newbie 5 10-25-2012 09:19 AM
Find and Replace character/special character from the file MyRelam Red Hat 8 05-21-2012 12:52 AM
Replace a complex line in lvm.conf phswartz Programming 3 05-20-2011 11:34 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:13 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration