The officially official Devuan Forum!

You are not logged in.

#1 2021-05-11 13:02:07

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

awk help ?

Can i pick someone's brains on how to modify this command ?

I have the command working ok, i just want to put in a few spaces at the beginning, think of it as padding.

ratpoison -c "info" | awk  '{ print substr($3,1)}'

this prints in any given window im in through dzen2 panel as follows.

0(XTerm)

what i would like is to have a space or two in front so it prints like so with a space or two as padding.

 0(XTerm)

edit: the full output of the command would be so before filtering it through awk...

(39, 136) 0(XTerm)

Last edited by dice (2021-05-11 13:22:27)

Offline

#2 2021-05-11 14:00:46

andyprough
Member
Registered: 2019-10-19
Posts: 100  

Re: awk help ?

I'm no awk wizard, but what works for me on the 'uname -a' command is to prepend the argument variable with "   ":

$ uname -a | awk '{print substr("   "$3,1)}'
   4.19.0-16-amd64

Primary Computer - Commodore 64: Processor - MOS 6510/8500, 1.023MHz; Memory - 64kb RAM, 20kB ROM - 8k BASIC V2, 8k Kernel, 4k Character ROM; Display output - 320x200, 16 colours; OS - BASIC V2.0; Weight: 1.8kg

Offline

#3 2021-05-11 14:08:03

andyprough
Member
Registered: 2019-10-19
Posts: 100  

Re: awk help ?

Another way you can do it is print it with a tab before the output:

$ uname -a | awk '{print substr("\t"$3,1)}'
	4.19.0-16-amd64

Last edited by andyprough (2021-05-11 14:09:52)


Primary Computer - Commodore 64: Processor - MOS 6510/8500, 1.023MHz; Memory - 64kb RAM, 20kB ROM - 8k BASIC V2, 8k Kernel, 4k Character ROM; Display output - 320x200, 16 colours; OS - BASIC V2.0; Weight: 1.8kg

Offline

#4 2021-05-11 14:15:59

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: awk help ?

Thanks andyprough, that works but only on the command line, i think my issues are with dzen2 and ratpoison window manager.

Offline

#5 2021-05-11 15:10:58

andyprough
Member
Registered: 2019-10-19
Posts: 100  

Re: awk help ?

You can play around with printf, maybe that will give you something you can use:

uname -a | awk {'printf("%s\n", "   "$3,1)'}
   4.19.0-16-amd64
uname -a | awk {'printf("%s\n", "\t"$3,1)'}
	4.19.0-16-amd64

Last edited by andyprough (2021-05-11 15:16:52)


Primary Computer - Commodore 64: Processor - MOS 6510/8500, 1.023MHz; Memory - 64kb RAM, 20kB ROM - 8k BASIC V2, 8k Kernel, 4k Character ROM; Display output - 320x200, 16 colours; OS - BASIC V2.0; Weight: 1.8kg

Offline

#6 2021-05-11 18:14:24

andyprough
Member
Registered: 2019-10-19
Posts: 100  

Re: awk help ?

I think that you are right that it is a ratpoison issue. I just checked and these commands are working on my standard DWM with dmenu when piped through dzen2, especially the forms with  "   " prepended. The tabbed forms "\t" are not as good as they create a space but fill it with a small box.


Primary Computer - Commodore 64: Processor - MOS 6510/8500, 1.023MHz; Memory - 64kb RAM, 20kB ROM - 8k BASIC V2, 8k Kernel, 4k Character ROM; Display output - 320x200, 16 colours; OS - BASIC V2.0; Weight: 1.8kg

Offline

Board footer