Sponsored Content
Top Forums Shell Programming and Scripting [awk] printing value of a variable assignment from a file Post 302943996 by sea on Thursday 14th of May 2015 04:17:00 PM
Old 05-14-2015
[awk] printing value of a variable assignment from a file

Heyas

Me try to print only the value of a (specific) variable assignment from a file.

What i get (1):
Code:
:) tui $ bin/tui-conf-get ~/.tui_rc TUI_THEME

dot-blue
""
"$TUI_DIR_INSTALL_ROOT/usr"
"$TUI_DIR_INSTALL_ROOT/etc/tui"
"$TUI_PREFIX/share/doc/tui"
"$TUI_PREFIX/share/tui"
"/home/sea/.config/tui"
"$TUI_DIR_USER/logs"
"$TUI_DIR_SYSTEM/themes"
"/home/sea/.cache"
"/home/sea/.local/bin"
"/home/sea/.local/man/man1"
"/home/sea/.cache/tui.tmp~"
"$TUI_DIR_USER/loadlist.conf"
"$TUI_DIR_USER/apps.conf"
"$TUI_DIR_USER/user.conf"
"$TUI_DIR_USER/settings.conf"
"$TUI_DIR_CONF/tui.conf"

What i want: (2)
Code:
✔ tui $ bin/tui-conf-get ~/.tui_rc TUI_THEME

dot-blue

Code i got:
Code:
CONFILE="$1"
VARNAME="$2"
awk	'  
		/^#/  ||
		/^\[/  ||
		/!VAR/ { next }
		{
			if (VAR = $1) {
				if ("-z" != $2) {
					print $2
				}
			}
	}' VAR="$VARNAME" FS="=" "$CONFFILE"


The RC file looks like:
Code:
#/home/sea/.tui_rc
# This file is not ment to be changed manualy!
# Any change of this file may result in an unusable TUI.
# Do changes at your own risk!
#
#	Theme
#	Options are: 	default, default-red, dot-blue, dot-red, \
#			floating, mono, witch-purple, witch-yellow
#	See /usr/share/tui/themes
#
 	TUI_THEME=dot-blue
#
#	Paths
#
[ -z "$TUI_DIR_INSTALL_ROOT" ] &&  \
 	TUI_DIR_INSTALL_ROOT=""
[ -z "$TUI_PREFIX" ] && \
 	TUI_PREFIX="$TUI_DIR_INSTALL_ROOT/usr"
[ -z "$TUI_DIR_CONF" ] && readonly \
 	...
#
#	Files
#
[ -z "$TUI_FILE_TEMP" ] && readonly \
 	TUI_FILE_TEMP="/home/sea/.cache/tui.tmp~"
[ -z "$TUI_FILE_CONF_LOADLIST" ] && readonly \
 	TUI_FILE_CONF_LOADLIST="$TUI_DIR_USER/loadlist.conf"
...

What am i missing?
Tia
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Variable assignment for file names.

I am trying to process error files in selected directories. I can count the files that are there and export the contents to a file for either emailing or printing. The next step is to move the files to a processed directory with the name changed to .fixed as the last extension. for file in... (2 Replies)
Discussion started by: jagannatha
2 Replies

2. Shell Programming and Scripting

awk variable assignment in a file

Hi All, I have a little awk script which uses a variable (x): awk -v x=0 'NF != 6 { ++x } END { print "This batch had " x " errors out of ", NR" records"}' But when I've tried to put the command in a file I can't seem to declare the variable. I've managed to simplify the code so that I... (4 Replies)
Discussion started by: pondlife
4 Replies

3. Shell Programming and Scripting

variable assignment using awk

Guys, Could you please help me out. I need two values in two variables using awk from the o/p of grep. example:- grep sdosanjh <filename> sdosanjh myhostname myfilename NOW WHAT I WANT IS :- sdosanjh should be in variable (say NAME) myhostname should be in variable (say... (8 Replies)
Discussion started by: sdosanjh
8 Replies

4. Shell Programming and Scripting

AWK Variable assignment issue Ksh script

Hi There, I am writing a ksh script which assigns variable values from file "A" and passes that variables to file "B". While passing the parameters an additional "$" sign is being assigned to awk -v option. Could any one help me with this please. #!/bin/ksh head -1... (3 Replies)
Discussion started by: Jeevanm
3 Replies

5. Shell Programming and Scripting

awk variable assignment-- inside braces or not?

So, in awk, I've always put my variable assignments inside of the curly braces, just like dad, and grandpa, and the 26 generations before them. But today I came upon an awk statement that had them outside the braces-- blasphemy! Seriously, though, is there any practical difference? I was... (3 Replies)
Discussion started by: treesloth
3 Replies

6. Shell Programming and Scripting

Printing a variable column using awk

Hi everyone, Ok here's the scenario. I have a control file like this. component1,file1,file2,file3,file4,file5 component2,file1,file2,file3,file4,file5I want to do a while loop here to read all files for each component. file_count=2 while ] do file_name=`cat list.txt | grep... (2 Replies)
Discussion started by: The Gamemaster
2 Replies

7. Homework & Coursework Questions

problem with printing out variable in awk

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: couldn't print out stored variable in awk 2. Relevant commands, code, scripts, algorithms: i have in a... (5 Replies)
Discussion started by: ymc1g11
5 Replies

8. Shell Programming and Scripting

Variable assignment inside awk

Hi, Was hoping someone could help with the following: while read line; do pntadm -P $line | awk '{if (( $2 == 00 && $1 != 00 ) || ( $2 == 04 )) print $3,$5}'; done < /tmp/subnet_list Anyone know if it is possible to assign $3 and $5 to separate variables within the {} brackets? Thanks... (14 Replies)
Discussion started by: CiCa
14 Replies

9. Shell Programming and Scripting

Optimize multiple awk variable assignment

how can i optimize the following: TOTALRESULT="total1=4 total2=9 total3=89 TMEMORY=1999" TOTAL1=$(echo "${TOTALRESULT}" | egrep "total1=" | awk -F"=" '{print $NF}') TOTAL2=$(echo "${TOTALRESULT}" | egrep "total2=" | awk -F"=" '{print $NF}') TOTAL3=$(echo... (4 Replies)
Discussion started by: SkySmart
4 Replies

10. Shell Programming and Scripting

awk code to inspect variable before printing

i have a unique scenario id like help with. im currently running this command and it does what i want: printf '%s\n' "${RawContent}" | awk '/## Beginning Stages ##/,/## Ending Stages ##/' | awk '!/^#.*\!|^#\!|DefaultError/' Can this be shortened? I'm looking for something portable as... (8 Replies)
Discussion started by: SkySmart
8 Replies
times(1)                                                           User Commands                                                          times(1)

NAME
times - shell built-in function to report time usages of the current shell SYNOPSIS
sh times ksh times DESCRIPTION
sh Print the accumulated user and system times for processes run from the shell. ksh Print the accumulated user and system times for the shell and for processes run from the shell. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), sh(1), time(1), attributes(5) SunOS 5.10 15 Apr 1994 times(1)
All times are GMT -4. The time now is 02:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy