Preview of a bash conf file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Preview of a bash conf file
# 1  
Old 11-27-2015
Preview of a bash conf file

(solved,sry)
Heyas

I'd like to give a little preview of an existing conf file, but not showing comments or empty lines.
Sadly, either the output style is wrong, or not all values are printed.

My current issue is, that the first variable read (var) contains both, the first and the second (val) variable.

Content of: this.conf
Code:
one="some value"
# Comment
two=bool

Code:
GREP=\grep;SED=\sed;CONFIG=this.conf

$GREP -v ^"#" "$CONFIG"| \
	$SED s,"="," ",g | \
	while read -r var val;do
		[ -n "$var" ] && printf '\r%s\t = \t%s\n' "$var" "$val"
	done

But what i get is this:
Code:
one "some value" =
two bool =

Expected output:
Code:
one	 = 	"some value"
two	 = 	bool

In a previous i attempt, i had:
Code:
		#touch $TMP.cfg
		#printf "$($GREP -v '#' $CONFIG)" > $TMP.cfg
		#while read var val;do
		#	[ ! "#" = "${var:0:1}" ] && \
		#		[ -n "$var" ] && \
		#		printf '\r%s\t = \t%s\n' "$var" "$val"
		#done < $TMP.cfg

This had the output-stle as expected.
However, the last entry was not shown, and actualy i'm still trying to figure a 'for loop' for this.

Any ideas please?

EDIT:
Nevermind, should have used:
Code:
while IFS== read ....

EDIT2:
Doh, and this would have beein bash'ism, or so...
Code:
VARS=$(tui-conf-get -l "$CONFIG"|$GREP -v req)
#source "$CONFIG"
for var in $VARS;do
	tui-echo "$var" "${!var}"
done


Last edited by sea; 11-27-2015 at 12:59 PM.. Reason: /solved
# 2  
Old 11-27-2015
Wouldn't a simple sed do?
Code:
sed  -n '/^#/b; s,=,\t=\t,p' file
one    =    "some value"
two    =    bool

This User Gave Thanks to RudiC For This Post:
# 3  
Old 11-27-2015
Not really, as i'm passing 2 values to a command that expects two.
The used "printf '%s'" is just for compatibility/simulation.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Configure resolv.conf and nsswitch.conf

Hi, I've installed Solaris 11.3(live media) and configured DNS. Everytime I reboot the server, resolv.conf got deleted and it created a new nsswitch.conf. I used below to configure both settings: # svccfg -s dns/client svc:/network/dns/client> setprop config/nameserver = (xx.xx.xx.aa... (1 Reply)
Discussion started by: flexihopper18
1 Replies

2. Shell Programming and Scripting

Script to update rsyslog.conf and auditd.conf

Hello all, Newbie here. I'm currently tasked with updating rsyslog.conf and auditd.conf on a large set of servers. I know the exact logging configurations that I want to enable. I have updated both files on on a server and hope to use the updated files as a template for the rest of the... (3 Replies)
Discussion started by: Mide
3 Replies

3. Linux

Bash to append domain in search field of resolv.conf after vpnc connection in Linux

After vpn connection,I am not able to resolve any machines in remote gateway.It looks like remote domain is added to domain field instead of adding it to the Search field in /etc/resolv.conf I want the remote domain to add to search field along with local domain.Can anyone tell a bash or script... (2 Replies)
Discussion started by: jeremy_brett
2 Replies

4. UNIX for Advanced & Expert Users

Help me at squid.conf file

Hi all, i have a scenario below: <========> <=========> Internet With IP: -Local: 10.0.0.2 -Squid: 2NICs (10.0.0.1 and 192.168.100.1) -Internet: 192.168.100.2 * On Squid: hosting a website name www.sample.com * On Local: hosting a website name www.abc.sample.com * Complete DNS... (0 Replies)
Discussion started by: kidzer0
0 Replies

5. UNIX for Advanced & Expert Users

How can i tell which conf file it is using

i have this program running on my solaris and there are two identical config files, i am not sure which one is being used by this program but I am sure it uses one of them. I run lsof -p {pid} but it does not show which config file has been read by this program, what i am doing wrong? thanks (4 Replies)
Discussion started by: fedora
4 Replies

6. Solaris

basic question on sd.conf and lpc.conf file

Hello Guys, Do we need to configure this file only if we add SAN disk or even if we add local disk, do we need to modify? (4 Replies)
Discussion started by: mokkan
4 Replies

7. UNIX for Advanced & Expert Users

Configuring snmpd.conf and snmptrapd.conf

HI, I want a help for Configuring snmpd.conf and snmptrapd.conf (i.e Configuring SNMP) for receiving TRAPS in my networks. I am using RHEL4.0 OS. Please tell me How I can configure above two files in a proper way and at an advanced level. Especially I am getting... (2 Replies)
Discussion started by: jagdish.machhi@
2 Replies

8. IP Networking

snmptrap.conf file

Hi I tried a lot bt could not configure snmptrapd.conf... Can any one tell me the steps or give me the configured snmptrapd.conf file?? Its really important..Plz help me.. Thanx (0 Replies)
Discussion started by: swapna_me
0 Replies

9. Shell Programming and Scripting

lilo.conf | bash

hi i am first time here for post tread but i alredy spend some time for look what u are doing here and i think that is great.... i am very interesting in bash scripting so i now wanna make one script that is able to set up a lilo.conf on every machine .....where script is runned. for exemple... (1 Reply)
Discussion started by: bl00d
1 Replies
Login or Register to Ask a Question