[opensuse] Great One-Liner for Parsing Config Files
Listmates,
I'm always looking for easier ways to do things and pass along worthwhile
epiphanies as they occur. For the gurus, this is child's play, but I can recall
parsing config files as a newbie and I always wanted to get rid of the comments
and just look at the active config parameters. At that time, grep, sed, awk and
the like just looked like word fragments from a foreign language.
Continuing in that tradition, here is another post concerning making it easy
to parse config files to get to the "beef". From the command line, a great
one-liner that will do this is:
Command Line: sed -e '/^[/s]*$/d' -e '/^\s*[#;]/d'
On Tue, 22 Jul 2008 06:01:16 David C. Rankin wrote:
Listmates,
I'm always looking for easier ways to do things and pass along worthwhile epiphanies as they occur. For the gurus, this is child's play, but I can recall parsing config files as a newbie and I always wanted to get rid of the comments and just look at the active config parameters. At that time, grep, sed, awk and the like just looked like word fragments from a foreign language.
I can relate to that. For me it still does...
Continuing in that tradition, here is another post concerning making it easy to parse config files to get to the "beef". From the command line, a great one-liner that will do this is:
Command Line: sed -e '/^[/s]*$/d' -e '/^\s*[#;]/d'
Nobody wants to type "sed -e '/^[/s]*$/d' -e '/^\s*[#;]/d'
Now when you want to parse a config file, it is as easy as:
nc filename
See? I always 'sed' it was a powerful tool, if only one knew how to use it...;-) Seriously, thanks Dave for another Really Useful Post. This one definitely gets filed away in my toolbox. :-) -- =================================================== Rodney Baker VK5ZTV rodney.baker@iinet.net.au =================================================== There were in this country two very large monopolies. The larger of the two had the following record: the Vietnam War, Watergate, double- digit inflation, fuel and energy shortages, bankrupt airlines, and the 8-cent postcard. The second was responsible for such things as the transistor, the solar cell, lasers, synthetic crystals, high fidelity stereo recording, sound motion pictures, radio astronomy, negative feedback, magnetic tape, magnetic "bubbles", electronic switching systems, microwave radio and TV relay systems, information theory, the first electrical digital computer, and the first communications satellite. Guess which one got to tell the other how to run the telephone business?
Rodney Baker wrote:
See? I always 'sed' it was a powerful tool, if only one knew how to use it...;-)
Seriously, thanks Dave for another Really Useful Post. This one definitely gets filed away in my toolbox. :-)
Glad you find it useful. Now all I have to do is wait on the Linux God for my next epiphany.... Like you sed once I figure out sed, they say it is quite useful ;-) -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Rodney Baker wrote:
See? I always 'sed' it was a powerful tool, if only one knew how to use it...;-)
Seriously, thanks Dave for another Really Useful Post. This one definitely gets filed away in my toolbox. :-)
Glad you find it useful. Now all I have to do is wait on the Linux God for my next epiphany.... Like you sed once I figure out sed, they say it is quite useful ;-)
Or you can do : cat <filename> | egrep -v "^[[:space:]]*$|^#" -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Mukul Singh wrote:
David C. Rankin wrote:
Rodney Baker wrote:
See? I always 'sed' it was a powerful tool, if only one knew how to use it...;-)
Seriously, thanks Dave for another Really Useful Post. This one definitely gets filed away in my toolbox. :-)
Glad you find it useful. Now all I have to do is wait on the Linux God for my next epiphany.... Like you sed once I figure out sed, they say it is quite useful ;-)
Or you can do :
cat <filename> | egrep -v "^[[:space:]]*$|^#"
I like it, but from what I can tell it doesn't handle the '^:space:#' or
'^:space:;' or '^;' situations. I used to rely on egrep alot until working to
eliminate '|' pipes in my expressions. Then, it becomes apparent that the
flexibility in sed with the ability to author multiple expressions for the same
input without piping wins hands down. Using your expression, I would have first
eliminated the pipe and cat all together rewriting as:
egrep -v "^[[:space:]]*$|^#" <filename>
No need for two commands with a pipe in the middle where one will do. However,
you did help me catch a typo in what I had posted. The expression should have been:
sed -e '/^\s*$/d' -e '/^\s*[#;]/d'
Mukul Singh wrote:
cat <filename> | egrep -v "^[[:space:]]*$|^#"
David C. Rankin wrote:
...
sed -e '/^[/s]*$/d' -e '/^\s*[#;]/d' <$1
...
Great commands! Into my toolbox! Just what I was wanting to do on Monday .... To be fecescious, and keeping the nitty-gritty (so no one will quickly fathom what is going to happen in an IP-tables rules script or other config files for instance), just call/run such a comment free shell script at startup, e.g. ncIPrules.sh. ( Do sed -e '/^[/s]*$/d' -e '/^\s*[#;]/d' iprules.sh>ncIPrules.sh and then add ' up "/bin/bash /etc/scripts/ncIPrules.sh" ' in a firewall config file that is loaded before the rules are loaded into the kernel). :-) Al -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Or you can do :
cat <filename> | egrep -v "^[[:space:]]*$|^#"
Doh, useless use of cat award. -- Brian K. White brian@aljex.com http://www.myspace.com/KEYofR +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk! -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
Brian K. White
-
David C. Rankin
-
LLLActive@GMX.Net
-
Mukul Singh
-
Rodney Baker