Skip to content

Tag: printf

AWK to print subnet

My requirement is to print a subnet value to I tried as below but i got output like this How to get output using awk as below Answer Good attempt and you were close, try following. With OP’s approach we need to put [ and ] as field separator too, so that we could catch the exact needed

Printing awk output in same line after grep

I have a very crude script that gets me information from all files with name FILENAME1 and FILENAME2 in all subfolders and the path of the subfolder. The awk result should only pick the nth line from FILENAME2 if the script is called with “ n”. I want all the info printed in one line! The problem is that

What’s the function of `’` in `printf “%x” “‘你”`?

I want to get the hexadecimal value of 你, someone tell me to use printf “%x” “‘你”, but I don’t know what’s the function of ‘ in printf “%x” “‘你”, why use ‘ before 你? Answer From the bash manual: Arguments to non-string format specifiers are treated as C constants, except that a leading plus or minus sign is allowed,

advanced printf explanation in bash

I just found this programming segment in my son’s Bash file. I am quite a newbie and unable to understand the printf syntax. Can someone explain me the COMMENTED printf in the segment below?? Answer It’s is nothing but a busy/wait spinner and the lines commented do nothing but set a blue foreground color and the last erases the line

Printf tab character as hex

In a restricted shell i have only access to execute printf (no awk, hexdump, xxd, …), so i used this script to print a file as hex: issue: last line (printf %02x ‘${a:$i:1}) does not work for some character like s,r,n,t,… i handle space character with (printf “%X” ‘ ‘) but does not work for r,t and n but it

Adding newline character to printf() changes code behaviour

For some reason, adding n to printf() changes the behaviour of below code. The code without n prints (null) whereas the code with n leads to Segmentation fault. Printf.c Printf.c – Output Printf_Newline.c Printf_Newline.c – Output I am curious to understand the reason behind this. Answer Both are undefined behavior, so an answer could stop right here. But there’s at