Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-19-2021, 02:46 PM   #1
LQ Newbie
Registered: Jan 2012
Posts: 14

Rep: Reputation: Disabled
Awk in Yad file replace existing value

My current bash script is:


# Variables

# Backup file first
cp $fileloc $fileloc.backup

widedit=`(yad --title="Linux Lite - Widget Editor" --borders=20 --text="All fileds <span font='Roboto Bold 12'>MUST</span> have a value:\n" --form \
--field="Gap X (0 - total monitor width span in pixels): ":NUM '!0..100000!1' \
--field="Gap Y (0 - total monitor height span in pixels): ":NUM '!0..100000!1' \
--field="Transparent (yes or no ):":CB yes!no! \

# Write to configuration file

echo $widedit | awk '{ sub(/gap_x/,"gap_x "$1); print }' >> $fileloc
echo $widedit | awk '{ sub(/gap_x/,"gap_x "$2); print }' >> $fileloc
echo $widedit | awk '{ sub(/gap_x/,"gap_x "$3); print }' >> $fileloc

exit 0
I'm wanting to have the line in /home/jerry/scripts/widget that shows gap_x 65 to read the value I input into the yad box, then overwrite the existing value in the widget file. At this point I am stuck. Thank you in advance.
Old 05-19-2021, 03:20 PM   #2
Senior Member
Registered: Mar 2020
Posts: 2,321

Rep: Reputation: Disabled
1) What is the point of invoking yad in a subshell? Did you confuse old and new syntax for command substitution [backticks vs. $(...)]?

2) In Bash, I would quote 'yes!no!'.

3) yad will print values separated by vertical bars like 30|50|yes|, so you have to specify | as delimiter for awk. Alternatively, you could specify --separator=' ' as an option to yad.

4) The output of yad doesn't include the string gap_x, so trying to substitute it is pointless.

5) Moreover, I don't understand why you're doing it thrice.
echo '30|50|yes|' |
  awk -F\| -vf="$fileloc" '{print"gap_x",$1>f}'
If what you want are all parameters, then
echo '30|50|yes|' |
  awk -F\| -vf="$fileloc" '
    print "gap_x",       $1 >f
    print "gap_y",       $2 >f
    print "transparent", $3 >f

Last edited by shruggy; 05-19-2021 at 03:58 PM.
Old 05-19-2021, 03:59 PM   #3
LQ Newbie
Registered: Jan 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
There were some wording errors in my first post, now corrected. Thank you for your reply.
This is the conky widget file:

# Conky Widget

# Gap between borders of screen and text
# Same thing as passing -x at command line
gap_x 65
gap_y 25

# Use Xft?
use_xft yes

# Xft font when Xft is enabled
#xftfont Bitstream Vera Sans Mono:size=8
#xftfont Terminus:size=10

# Text alpha when using Xft
xftalpha 0.8

# Update interval in seconds
update_interval 1.0

# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0

# Create own window instead of using desktop (required in nautilus)
own_window yes
#own_window_colour grey
own_window_argb_visual yes
own_window_transparent yes
own_window_argb_value 0
own_window_type normal
own_window_class conky-semi
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

# Use a background image
background yes

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# Minimum size of text area
minimum_size 300 200

# Maximum width of widget
maximum_width 310

# Draw shades?
draw_shades yes

# Draw outlines?
draw_outline no

# Draw borders around text
draw_borders no
draw_graph_borders yes

# Stippled borders?
#stippled_borders 8

# border margins
#border_margin 4

# border width
#border_width 1

# Default colors and also border colors
default_color white
color2 9fee62 # System is up to date
color3 ff4343 # Red - Number of Updates Available

default_shade_color black
default_outline_color white

# Text alignment, other possible values are commented
alignment bottom_right

# Subtract file system buffers from used memory?
no_buffers yes

# Set to yes if you want all text to be in uppercase
uppercase no

# Number of cpu samples to average
# set to 1 to disable averaging
cpu_avg_samples 2

# Number of net samples to average
# Set to 1 to disable averaging
#net_avg_samples 2

# Force UTF8? note that UTF8 support required XFT
override_utf8_locale yes

# Width and thickness of ${hr 2} bar separator
default_bar_size 150 5

# Lua rounded corners requirements
lua_load /etc/conky-lite/draw_bg.lua
lua_draw_hook_pre draw_bg 
imlib_cache_size 0

# Distance of text from edge of widget
border_outer_margin 10

own_window_colour 000000
${image /etc/conky-lite/logo.png -p 110,100}
${alignc}${font Noto Sans:bold:size=16}${color ffe082}${exec cat /etc/llver}${font}
${alignc}${color}${time %A, }${time %e %B %Y}
${color slate grey}${hr 2}

${alignc}${font Noto Sans:bold:size=13}${color ffe082}System Information${font}
${color}CPU Usage:	${alignr}$cpu%
${color}Memory Total:	${color}${alignr}${memmax}
${color}Memory Used:	${color}${alignr}${mem}
${color}Logged in as:	${alignr}${color}$USER
${color}Firewall Status:	${alignr}${execpi 5 /etc/conky-lite/fwchk}
${color}${alignc}${exec /usr/bin/acpi | awk '{print $1,$3,$4,$5}'}
${color slate grey}${hr 2}

${alignc}${font Noto Sans:bold:size=13}${color ffe082}Update Status${font}
${alignc}${execpi 300 /etc/conky-lite/updates}
I want to overwrite the values below that are in the conky widget file, to whatever I input into the yad boxes, and leave the rest of the file intact.

gap_x 65
gap_y 25
own_window_transparent yes
Yes, I'm no bash guru, that is why I am here, for help and guidance. Cheers.
Old 05-19-2021, 04:19 PM   #4
Senior Member
Registered: Mar 2020
Posts: 2,321

Rep: Reputation: Disabled
<<! IFS='|' read gapx gapy xpar
$(yad ...)
sed -Ei '/^gap_x\>/s/\S+$/'"$gapx"'/
         /^own_window_transparent\>/s/\S+$/'"$xpar/" "$fileloc"
In Bash, you could also use HERE string instead of HERE document, or redirect from process substitution.

Last edited by shruggy; 05-19-2021 at 04:35 PM.
2 members found this post helpful.
Old 05-19-2021, 09:35 PM   #5
LQ Newbie
Registered: Jan 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Thank you shruggy, that worked well, plus I learned a lot. Many thanks


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
LXer: Multiple-item data entry with YAD LXer Syndicated Linux News 0 04-07-2014 11:51 AM
[SOLVED] replace local value variable with new value from script Bharath_ Linux - Newbie 2 05-22-2013 11:02 AM
strange value assignments variable = value, value?? ostrow30 Programming 2 07-24-2011 07:59 AM
difference between value *value and value * value PoleStar Linux - Newbie 1 11-26-2010 03:37 PM
[SOLVED] How to debug undefined reference to library function (yad 0.5.1)? catkin Linux - Software 3 10-17-2010 07:08 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:27 PM.

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