Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 04: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, 01:43 PM   #2
Ser Olmy
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 2,508

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, 04:45 PM   #3
Registered: Dec 2011
Location: Simplicity
Posts: 980

Rep: Reputation: 424Reputation: 424Reputation: 424Reputation: 424Reputation: 424
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 04: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 07:37 PM
Replace second character instead of first Drigo Linux - Newbie 5 10-25-2012 10:19 AM
Find and Replace character/special character from the file MyRelam Red Hat 8 05-21-2012 01:52 AM
Replace a complex line in lvm.conf phswartz Programming 3 05-20-2011 12:34 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:37 AM.

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