[root@localhost ~]# echo 123456 123456 [root@localhost ~]# echo 1 2 3 4 5 6 #按照原格式输出 1 2 3 4 5 6 [root@localhost ~]# printf 1 2 3 4 5 6 #只输出了一个符号,没有标称输出类型 1[root@localhost ~]# printf %s 1 2 3 4 5 6 123456[root@localhost ~]# printf %s %s %s 1 2 3 4 5 6 #单引号不能省略,省略后会把第一个特殊符号后的内容都定义为字符串 %s%s123456[root@localhost ~]# printf '%s %s %s' 1 2 3 4 5 6 #输出三个字符串内容,用空格隔开,6 个字符串内容分两次输出 1 2 34 5 6[root@localhost ~]# printf '%s\t%s\t%s\n' 1 2 3 4 #字符之间用制表符隔开,每三个用一个换行符 1 2 3 4 5 6 [root@localhost ~]# printf student.txt #读取文件名 student.txt[root@localhost ~]# echo student.txt #读取文件名 student.txt [root@localhost ~]# printf $(cat student.txt) #没有标称输出内容,不能正确识别,通过变量来读取文件内容 ID[root@localhost ~]# printf '%s' $(cat student.txt) #不调整输出格式,没有分隔符,所有内容被识别为一个字符串 IDNameGenderMark1stu1F952stu2F853stu3F75[root@localhost ~]# printf '%s\t%s\t%s\t%s\n' $(cat student.txt) #调整格式输出 ID Name Gender Mark 1 stu1 F 95 2 stu2 F 85 3 stu3 F 75 [root@localhost ~]# cat student.txt | printf #管道是数据流操作,printf 不支持数据流操作 printf: usage: printf [-v var] format [arguments]在 awk 命令的输出中支持 print 和 printf 命令 print:print 会在每个输出之后自动加一个换行符(Linux 默认没有 print 命令,print 命令是 awk 命令的子命令) printf:printf 是标准格式的输出命令,并不会自动加入换行符,如果需要换行,则需要手工加入换行符 Linux 中的标准输出是 printf awk 语句中只识别 printf 命令,不识别 echo 命令 printf 不支持数据流
如对本文有疑问, 点击进行留言回复!!
MySql添加新用户及为用户创建数据库和给用户分配权限方法介绍
Navicat出现无法远程连接MySql服务器问题的解决办法
网友评论