LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 12-14-2017, 03:09 PM   #1
gartie
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.

thanks..

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

Rep: Reputation: Disabled
You could try:
Code:
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
MadeInGermany
Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 788

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

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


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:25 PM.

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