Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

printf @ bash

printf "My brother %s is %d years old.
" Prakash 21
Comment

printf in bash

printf "$your_var1 $your_var2 $(tail -n -1 your.log | grep Word_to_grep ) 
" >> ../opt_done.txt 

# several things, 
# printf with 
 new line
# $(tail -n -1 your.log | grep Word_to_grep )  --> is a command, will output whats comes in terminal
			(if final line of the document has "Normal" to grep it will grep, oherwise nothing 
# $your_var1 $your_var2 variables
# >> this is an appending,
Comment

printf linux

#cat file.txt
#1.11135 -66.8286 0.382867 24.6386 0.693014 175.409 0.763907 -97.6113

cat file.txt | awk '{printf "%-5s%-10s%8s%10s
","A",$1,$2,"-1.0"}'
	                           ^%-5start from left, keep 5 digit space to right					
                                	  ^%8 start from right, keep 8 digit space to letf
output : 
 1    1.11135   -66.8286      -1.0
#123451234567890123456781234567890

%s	a string of characters
%c	character
%d	decimal (integer) number (base 10)
%e	exponential floating-point number
%f	floating-point number
%i	integer (base 10)
%%	print a percent sign
\%	print a percent sign


#advacne version of this, with many new lines, 

cat file.txt | awk '{printf "%-5s%-10s%8s%10s
%-5s%-10s%8s%10s
","A",$1,$2,"-1.0","B",$3,$4,"-2.0"}'
							 ------------------^repeat								

var=0.00
awk '{printf "%4s%7.0f%3s%6s%2s%4.0f%12.3f%8.3f%8.3f%6.2f%7.2f
", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $var}' < a.pdb >> dest.pdb

more https://alvinalexander.com/programming/printf-format-cheat-sheet/
Comment

PREVIOUS NEXT
Code Example
Shell :: install chocolatey on windows 
Shell :: gatsby transformer remark 
Shell :: vscode restart window 
Shell :: vscode Error: EACCES: permission denied 
Shell :: open files from terminal linux 
Shell :: bash loading bar spinner in bash shell script 
Shell :: Install Software GUI GNOME for Kali Linux 2022.1 
Shell :: uninstall nvidia x server ubuntu 
Shell :: git commit specific files 
Shell :: zip command line 
Shell :: install express globally 
Shell :: fedora linux 
Shell :: debian install nvidia driver 
Shell :: scp remote to local 
Shell :: init jest config 
Shell :: benchmark a network drive windows without installing 
Shell :: check all running processes linux 
Shell :: push docker image to docker hub 
Shell :: helm cheat sheet 
Shell :: brew upgrade 
Shell :: tar exclude multiple directories 
Shell :: find logs in kubernetes pods 
Shell :: install netbeans 8.2 in kali linux 
Shell :: delete file on git 
Shell :: ubuntu locate binary file 
Shell :: aws cli on heroku 
Shell :: remove folder from gitlab main branch repository 
Shell :: Git - delete specific branch 
Shell :: bash script cd into script dir 
Shell :: Please install mariadb package manually 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =