My use case is as follows. file.txt First arg: %s Second %s arg, Third %s Run prog file.txt “one” “$(ls dir1/dir2)” “three” Resulting in First arg: one Second file1 file2 file3 arg, Third three I first thought to use sed but that inevitably runs into problems when bash substitutions get read as format characters like this sed s/%1/$VAR/g -> sed
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 the exact needed
Calling printf() in assembly causes a ‘floating point exception’
I have the following code: I compile it with nasm -f elf64 1.asm and link it using ld -dynamic-linker /lib/ld-linux-x86-64.so.2 1.o -o 1 -lc. When I execute the binary, I get printf() doesn’t always fail when I call it in assembly code. Removing printf() calls from printax and printbx gives me Update: The exception also disappears if I remove the
Printing current time in milliseconds or nanoseconds with printf builtin
We can print the current time with the builtin printf function, without needing to invoke an external command like date, like this: How can we make printf to print milliseconds or nanoseconds as well? Using %3N or %N in the format string doesn’t work: However, the date command works fine: This is on a Red Hat Linux version 7.3. Answer
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 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
Printf makes program work in C, htonl and ntohl not working?
This is for a Linux system, in C. It involves network programming. It is for a file transfer program. I’ve been having this problem where this piece of code works unpredictably. It either is completely successful, or the while loop in the client never ends. I discovered that this is because the fileLength variable would sometimes be a huge (negative