Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 03-25-2010, 05:02 PM   #1
LQ Newbie
Registered: Mar 2010
Location: Budapest
Distribution: Debian
Posts: 8

Rep: Reputation: 0
General tool to manipulate text configuration files

Is there any Linux tool to create new or modify exiting key/value pairs in text configuration files? For example, to change a setting in xorg.conf, or change something in etc/networking/interfaces?

I know it could be done by sed or by perl scripts, but it could be easier to have a program for this purpose. There are many difficulties for this job that the program should consider, and I am facing nearly all of them:

- Some configuration files may have sections. Like in Windows-type INI files (for example: "[something]"), or like “Section” in xorg.conf. More sections with the same name can occur, like in xorg.conf.

- If the key/value pair originally does not exist, then the program should add it. But not to the end of the file, but tothe end of a predefined section.

- Config files can have remark lines. Remark text can be even at the same line than the key/value pair. After modifying the value, the original remark text should not change at the end of the line. The remark-starting symbol is not always “#”, but some times ”;” or “!” or “ //”

- The values in configuration files are not always simple numbers or simple words, but in rare cases, they are composed by more words, for example:

item=name address phone

And of course, we can have remark at the end, like this:

item=name address phone # remark text

- The key-value separator depends on the file. Some files use "key=value" format, some other use "key value" format, or even "key1 key2 value", like xorg.conf. The “:” as separator can also occur.

- Case sensitivity can also be an issue.

- Sometime to desired task is not to modify a value, but to add or remove a line beginning remark to a certain line.

I think that managing all these possible cases by a perl or sed program is nearly impossible. I begun to write a C program, but maybe there is already one?
Old 03-26-2010, 06:18 PM   #2
Andrew Benton
Senior Member
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 64
I've never heard of a GUI for editing xorg.conf, I've always just done it with a text editor. The way xorg server is going, /etc/X11/xorg.conf is becoming optional. The xorg server should pick sensible defaults for most things. You should only need to put tweaks in xorg.conf
Old 03-26-2010, 06:57 PM   #3
Registered: Feb 2009
Distribution: FreeBSD, OpenBSD, NetBSD, Debian, Fedora
Posts: 770
Blog Entries: 52

Rep: Reputation: 68
If the file requires root permissions, and you want to edit as the normal user, then you need to use chown and/or chmod to edit as the normal user.
After that, you can use kate, ooo, gedit, scite, etc.
Make a backup before you do such.
Old 03-27-2010, 04:24 AM   #4
LQ Newbie
Registered: Mar 2010
Location: Budapest
Distribution: Debian
Posts: 8

Original Poster
Rep: Reputation: 0
I would like to automate the modifications of the config files, so I would like to make the modification from scripts, not manually. And I don't only think to xorg.conf.
Actually, I have a tinny Linux, that can boot in several different PC's, in several networking setups and with several different resolution VGA monitors.
I would like to collect into one config files all the main settings that need to be modified for a given environment. These settings can be: static IP address or DHCP, VGA resolution, DPI value of Xwindow, font size for terminal, etc.

To quickly move from one hardware/network setup to an other, one should modify only this main config file, and a special script should write all the settings from this file into the corresponding target setup files: xorg.conf, ~/.XDefaults, X starting script (for DPI setting), /etc/network/interfaces, etc.

Old 03-27-2010, 04:31 AM   #5
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,040

Rep: Reputation: 1409Reputation: 1409Reputation: 1409Reputation: 1409Reputation: 1409Reputation: 1409Reputation: 1409Reputation: 1409Reputation: 1409Reputation: 1409
What you seem to be describing is basically what debconf does. You could look into using it.

Old 03-27-2010, 05:46 AM   #6
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 404Reputation: 404Reputation: 404Reputation: 404Reputation: 404
There's no universal tool for this, because every distro does many things its own way.

Some distributions do have specific tools or frontends for this purpose. For example SuSE's Yast(2).
Old 03-28-2010, 08:31 PM   #7
LQ Newbie
Registered: Mar 2010
Location: Budapest
Distribution: Debian
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks for the replies!
I use Debian 4 with Fluxbox window manager, on embedded PC's with limited resources. So I cannot use a bigger graphical configuration program. I've read something about DebConf. Maybe I could write my own front-end for DebConf and use it both to get a text based GUI and to apply the settings in target config files.
However, meanwhile I finnished my C program that can manipulate config files.
In my system, now I have one main configuration file. I also have a script in "/etc/init.d" that reads the settings from the main config file. Then the settings are written into one or more lines in system config files by my C program
(target files are: xorg.conf, /etc/networking/interfaces, /etc/hosts, /etc/hostname, ~/.Xdedefeaults files).

Now I am thinking to make available this C program for the public. I think it could be useful for others. With only one line in a script one can modify, for example, the XKbLayout item in xorg.conf.


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Way to manipulate a text file.. php ? 8rucech85 Programming 2 01-30-2008 04:35 AM
tool to extract text from various files with sql-queries?? xomic Linux - Software 1 04-17-2007 09:44 PM
MythTV GUI configuration error (Where are the text config files?) GTBlackwell Linux - Software 1 07-26-2006 11:57 PM
Tool for Linux to manipulate the fan on Thinkpad? Haraldsh Debian 4 04-04-2005 11:03 AM
What's the purpose of tar.gz files and how do I manipulate them? altair401 Linux - Newbie 7 12-21-2003 07:41 PM > Forums > Linux Forums > Linux - Software

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