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
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 04:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy