当前位置:网站首页>awk从入门到入土(3)awk内置函数printf和print实现格式化打印
awk从入门到入土(3)awk内置函数printf和print实现格式化打印
2022-07-03 02:13:00 【奇妙之二进制】
awk中print与printf的主要差别显示在以下两点:
- print在显示多个结果的时候以逗号分隔,结果将这几部分的内容自动使用输出分隔符(字段输出分割符默认是空格,记录输出分割符默认是换行符)进行分隔,且不需要添加换行符\n;如果不使用,间隔,则打印时会连在一起,即使使用了空格:
[email protected]:~$ awk -F: 'BEGIN{k=1} {print $1,$2}' /etc/passwd
root x
daemon x
bin x
sys x
[email protected]:~$ awk -F: 'BEGIN{k=1} {print $1 $2}' /etc/passwd
rootx
daemonx
binx
sysx
syncx
gamesx
- printf可以更加灵活的控制某一个字段的输出格式,通过使用诸如%-12s,%3.1f等格式化方法。printf更加接近使用C语言的同学的习惯。
$ awk -F: 'BEGIN{k=1} {printf "%s,%s
边栏推荐
- 苏世民:25条工作和生活原则
- Asian Games countdown! AI target detection helps host the Asian Games!
- Storage basic operation
- Face recognition 6-face_ recognition_ Py based on OpenCV, face detection and real-time tracking using Haar cascade and Dlib Library
- Coroutinecontext in kotlin
- Explore the conversion between PX pixels and Pt pounds, mm and MM
- 可視化yolov5格式數據集(labelme json文件)
- 树形结构数据的处理
- Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly
- Visual yolov5 format data set (labelme JSON file)
猜你喜欢
Rockchip3399 start auto load driver
通达OA v12流程中心
Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)
[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)
Anna: Beibei, can you draw?
Analysis, use and extension of open source API gateway apisex
全链路数字化转型下,零售企业如何打开第二增长曲线
[leetcode] 797 and 1189 (basis of graph theory)
easyExcel
Recommendation letter of "listing situation" -- courage is the most valuable
随机推荐
疫情当头,作为Leader如何进行团队的管理?| 社区征文
力扣(LeetCode)183. 从不订购的客户(2022.07.02)
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)
苏世民:25条工作和生活原则
Where is the future of test engineers? Confused to see
缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
RestCloud ETL 跨库数据聚合运算
通达OA v12流程中心
詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信
Exception handling in kotlin process
[camera topic] how to save OTP data in user-defined nodes
SPI机制
Huakaiyun (Zhiyin) | virtual host: what is a virtual host
Asian Games countdown! AI target detection helps host the Asian Games!
DDL basic operation
Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)
Basic operation of view
What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)
【CodeForces】CF1338A - Powered Addition【二进制】