Skip to content

Tag: printf

AWK to print subnet 0.69.100.in-abc.def

My requirement is to print a subnet 100.69.0.0/10 value to 0.69.100.in-abc.def. 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…

Printing awk output in same line after grep

I have a very crude script getinfo.sh 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 “getinfo.sh n”. I want all the info printed in o…

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 foregroun…

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” ‘ ‘…

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 …