LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2012, 02:31 AM   #1
essahar
LQ Newbie
 
Registered: Jun 2006
Distribution: Red Hat Enterprise Linux
Posts: 12

Rep: Reputation: 0
sed to add between two pattern


Hello all

I have an xorg.conf file and I want to add some extra setting in a section below is the file

Quote:
Section "InputDevice"

# generated from default
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/input/mice"
Option "Emulate3Buttons" "no"
Option "ZAxisMapping" "4 5"
EndSection
Section "ServerLayout"
Identifier "single head configuration"
Screen 0 "Screen0" 0 0
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
Option "Xinerama" "0"
EndSection

Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
EndSection
I want to add after the 'Section "ServerLayout"' and just above the first occurrence of EndSection the below line:

Option "BlankTime" "0"
Option "StandbyTime" "0"
Option "SuspendTime" "0"
Option "OffTime" "0"

I appreciate your help
 
Old 04-08-2012, 02:46 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Deleted answer, didn't see the "sed" part of the question.

Last edited by repo; 04-08-2012 at 02:48 AM.
 
Old 04-08-2012, 02:50 AM   #3
essahar
LQ Newbie
 
Registered: Jun 2006
Distribution: Red Hat Enterprise Linux
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for the answer

but I have to add this for more than 1000 Linux workstations and the file is not the same in all of them

Last edited by essahar; 04-08-2012 at 05:31 AM.
 
Old 04-08-2012, 02:59 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Here is one way using sed:
Code:
sed '/Section "ServerLayout"/,/EndSection/s/EndSection/Option "BlankTime" "0"\nOption "StandbyTime" "0"\nOption "SuspendTime" "0"\nOption "OffTime" "0"\nEndSection/' xorg.conf
Quote:
Originally Posted by essahar
but I have to add this for more than 1000 Linux workstations
Edit one instance and copy that one to the other machines.

Hope this helps.
 
1 members found this post helpful.
Old 04-08-2012, 03:19 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Code:
/Section "ServerLayout"/,/^$/{ /EndSection/i\
Option "BlankTime" "0"\
Option "StandbyTime "0"\
Option "SuspendTime" "0"\
Option "OffTime" "0"
}
You might want the first range to be /Section "ServerLayout"/,/EndSection/ instead. ServerLayout might not be the last section before a blank line in all hosts.
 
1 members found this post helpful.
Old 04-08-2012, 03:34 AM   #6
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

Here is a ed(1) script
Code:
/ServerLayout/
/EndSection/
i
Option "BlankTime" "0"
Option "StandbyTime" "0"
Option "SuspendTime" "0"
Option "OffTime" "0"
.
,p
#wq
Save it to some file, say, ins.ed and do
Code:
ed xorg.conf < ins.ed
Uncomment last line to write changes to file. The ,p command just prints the whole file to stdout.
 
1 members found this post helpful.
Old 04-08-2012, 05:11 AM   #7
essahar
LQ Newbie
 
Registered: Jun 2006
Distribution: Red Hat Enterprise Linux
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks everyone, I will write "jschiwal" command into a script and run it from a NFS folder mounted by all workstations.

Last edited by essahar; 04-08-2012 at 05:31 AM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] search, duplicate and add pattern with sed/awk lolworlds Programming 4 02-03-2012 10:17 AM
[SOLVED] add texts using sed in matching pattern manya Programming 5 02-03-2011 07:59 AM
[SOLVED] how to exclude everything except a pattern with sed rafaeldeoliveiracosta Programming 12 07-23-2010 11:36 AM
last pattern with sed? xpto09 Linux - Newbie 6 10-04-2007 08:01 PM
Sed pattern matching digitalbrutus Programming 1 08-20-2006 01:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:46 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
Open Source Consulting | Domain Registration