➜ linux printf %s $(cat df) <== printf不支持管道符`|`,使用$()的方式调用系统命令 FilesystemSizeUsedAvailCapacityiusedifree%iusedMountedon/dev/disk1233Gi50Gi182Gi22%131780334780321322%/devfs180Ki180Ki0Bi100%6240100%/devmap-hosts0Bi0Bi0Bi100%00100%/netmapauto_home0Bi0Bi0Bi100%00100%/home
可以看到,printf将df内容以字符串的形式直接输出,下面看下根据输出格式输出简单文本
1 2 3 4 5 6 7 8
# %-5s 格式为左对齐且宽度为5的字符串代替(-表示左对齐),不使用则是又对齐 # %-4.2f 格式为左对齐宽度为4,保留两位小数 ➜ linux printf"%-5s %-10s %-4s\n" NO Name Mark NO Name Mark ➜ linux printf"%-5s %-10s %-4.2f\n"01 Tom 90.3456 01 Tom 90.35 ➜ linux printf"%-5s %-10s %-4.2f\n"02 Jack 89.2345 02 Jack 89.23
awk
1 2 3 4 5 6 7 8
NAME awk - pattern-directed scanning and processing language
Awk scans each input file for lines that match any of a set of patterns specified literally in prog or in one or more files specified as -f progfile. With each pattern there
can be an associated action that will be performed when a line of a file matches the pattern. Each line is matched against the pattern portion of every pattern-action state-
ment; the associated action is performed for each matched pattern. The file name - means the standard input. Any file of the form var=value is treated as an assignment, not a
filename, and is executed at the time it would have been opened if it were a filename. The option -v followed by var=value is an assignment to be done before prog is executed;
any number of -v options may be present. The -F fs option defines the input field separator to be the regular expression fs.
An input line is normally made up of fields separated by white space, or by regular expression FS. The fields are denoted $1, $2, ..., while $0 refers to the entire line. If
FS is null, the input line is split into one field per character.
A pattern-action statement has the form
pattern { action }
A missing { action } means print the line; a missing pattern always matches. Pattern-action statements are separated by newlines or semicolons.
An action is a sequence of statements. A statement can be one of the following:
if( expression ) statement [ else statement ]
while( expression ) statement
for( expression ; expression ; expression ) statement
for( var in array ) statement
do statement while( expression )
break
continue
{ [ statement ... ] }
expression # commonly var = expression
print [ expression-list ] [ > expression ]
printf format [ , expression-list ] [ > expression ]
return [ expression ]
next # skip remaining patterns on this input line
nextfile # skip rest of this file, open next, start at top
delete array[ expression ] # delete an array element
delete array # delete all elements of array
exit [ expression ] # exit immediately; status is expression
DESCRIPTION -c The number of bytes in each input file is written to the standard output. This will cancel out any prior usage of the -m option. -l The number of lines in each input file is written to the standard output. -m The number of characters in each input file is written to the standard output. If the current locale does not support multibyte characters, this is equivalent to the -c option. This will cancel out any prior usage of the -c option. -w The number of words in each input file is written to the standard output.