#] #] ********************* #] "$d_SysMaint"'Linux/printf.txt' # www.BillHowell.ca 3Aug2023 initial # view in text editor, using constant-width font (eg courier), tabWidth = 3 #48************************************************48 #24************************24 # Table of Contents, generate with : # $ grep "^#]" "$d_SysMaint"'Linux/printf.txt' | sed "s/^#\]/ /" # #24************************24 # Setup, ToDos, #08********08 #] ??Aug2023 #08********08 #] ??Aug2023 #08********08 #] ??Aug2023 #08********08 #] ??Aug2023 #08********08 #] ??Aug2023 #08********08 #] 03Aug2023 printf basics, redirection to file +-----+ https://stackoverflow.com/questions/10947335/c-modifying-printf-to-output-to-a-file C modifying printf () to output to a file Asked 11 years, 1 month ago Modified 1 year, 11 months ago Viewed 32k times If you do not have liberty to modify the source code that does printing, you can use freopen on stdout to redirect to a file: stdout = freopen("my_log.txt", "w", stdout); This borders on a hack, however, because command-line redirects will stop working as expected. If you do have access to the code that does printing, using fprintf is preferred. You can also switch your stdout temporarily for a function call, and then put it back: FILE *saved = stdout; stdout = fopen("log.txt", "a"); call_function_that_prints_to_stdout(); fclose(stdout); stdout = saved; edited Jun 8, 2012 at 12:29 answered Jun 8, 2012 at 10:50 Sergey Kalinichenko +-----+ https://www.howtogeek.com/781474/how-to-use-the-bash-printf-command-on-linux/ How to Use the Bash printf Command on Linux The Bash printf command starts where echo ends. Dave McKay Published Mar 10, 2022 Other Escape Characters Here are some more escape characters you can use. You've already seen "\n" in action. \n: Moves down to a new line. \r: Prints a carriage return. This sends the output cursor back to the start of the current line. \t: Prints a tab character. \v: prints a vertical tab space. \\: Prints a backslash character. \": Prints a quotation character. \b: Prints a backspace character. These are the most common format specifiers. They are all preceded by a percent "%" sign. To print a percent sign, you use two percent signs together "%%." %s: Prints a string. %c: Prints a single character. %d: Prints an integer. %f: prints a floating point number. %u: Prints an unsigned integer. %o: Prints a value in octal. %x: Prints a value in hexadecimal, in lowercase. %X: Prints a value in hexadecimal, in uppercase. %e: Prints a floating point number in scientific notation, in lowercase. %E: Prints a floating point number in scientific notation, in uppercase. %%: Prints a percent "%" symbol. Using Variables Using variables with printf is very similar to using them with echo . To include a variable, like this environment variable, precede it with the dollar sign "$" as usual. printf "Home directory: $HOME\n" printf "%s%s %s\n" "How" "-To" "Geek" printf "Dec: %d\nOct: %o\nHex: %x\n" 15 15 15 +-----+ https://stackoverflow.com/questions/66437239/why-use-printf-s-n-message Why use printf '%s\n' "message"? Asked 2 years, 5 months ago Modified 2 years, 5 months ago Viewed 6k times printf is used for format and print data. In the case of: printf '%s\n' "No input entered" %s represents a string place holder for the space separated string that follows and "\n" represents a line feed. %s will then be substituted for "No input entered", followed by a line feed. nswered Mar 2, 2021 at 10:41 Raman Sailopal +-----+ https://askubuntu.com/questions/1253706/printf >>"$pLog"-format-space-and-s-n The bash shell builtin inherits its format specifiers from the corresponding C routines, so often the most useful reference is man 3 printf >>"$pLog". answered Jun 25, 2020 at 15:32m steeldriver # enddoc