Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

printf

#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

printf

<?php
$n =  43951789;
$u = -43951789;
$c = 65; // ASCII 65 is 'A'

// notice the double %%, this prints a literal '%' character
printf("%%b = '%b'
", $n); // binary representation
printf("%%c = '%c'
", $c); // print the ascii character, same as chr() function
printf("%%d = '%d'
", $n); // standard integer representation
printf("%%e = '%e'
", $n); // scientific notation
printf("%%u = '%u'
", $n); // unsigned integer representation of a positive integer
printf("%%u = '%u'
", $u); // unsigned integer representation of a negative integer
printf("%%f = '%f'
", $n); // floating point representation
printf("%%o = '%o'
", $n); // octal representation
printf("%%s = '%s'
", $n); // string representation
printf("%%x = '%x'
", $n); // hexadecimal representation (lower-case)
printf("%%X = '%X'
", $n); // hexadecimal representation (upper-case)

printf("%%+d = '%+d'
", $n); // sign specifier on a positive integer
printf("%%+d = '%+d'
", $u); // sign specifier on a negative integer
?>
Comment

printf

printf "Hello %s, I'm %s" Sven Olga
#=> "Hello Sven, I'm Olga

printf "1 + 1 = %d" 2
#=> "1 + 1 = 2"

printf "This is how you print a float: %f" 2
#=> "This is how you print a float: 2.000000"
Comment

PREVIOUS NEXT
Code Example
Shell :: github repository 
Shell :: android logs for app on terminal 
Shell :: Create github repo in command line 
Shell :: speed up ubuntu 
Shell :: remove mac ._ files windows 
Shell :: grep until third match 
Shell :: add geckodriver to path linux 
Shell :: github status 
Shell :: generate rs256 key pair 
Shell :: bash how to turn into root 
Shell :: setup mongodb locally on centos 8 
Shell :: delete all folders except one linux 
Shell :: for in shell script 
Shell :: ssh ubuntu version check 
Shell :: shortcut key for screenshot in windows 7 
Shell :: create powershell profile 
Shell :: string powershell 
Shell :: how to I paste in gitbash windows 
Shell :: install playit to ubuntu 
Shell :: scripting sobre ficheros 
Shell :: how to install wtforms on mac terminal 
Shell :: linux get notification if bettery full 
Php :: how to remove public from url in codeigniter 4 
Php :: list all files in directory php 
Php :: php redirect in seconds 
Php :: fluid inline if 
Php :: the $request argument is type-hinted with the non-existent class or interface: "AppControllerRequest". 
Php :: laravel passport generate key 
Php :: php filter_var boolean 
Php :: laravel show routes artisan 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =