linux中通过awk进行文本的对齐格式化处理?awk printf左对齐?
需求描述:
今天在对一个从excel文件中粘出来的内容进行整理的时候,发现格式很乱,就想用awk工具格式化一下,在此记录一下.
操作过程:
1.从excel中复制出来的内容
job_name job_group
syncCommStockJob dataSync
syncStoreChnlJob dataSync
syncOrderJob dataSync
syncReportStoreJob dataSync
hdfsScanJob report
orderSaleDailyJob report
jdzmdOrdersJob report
jdCanJob report
tbTermSalesJob report
ess3GTermSalesJob report
npBusiDayReportJob report
npBusiWeekMonthReportJob report
snOrdersScreenJob report
jdzmdOrderScreenJob report
jjTermSalesJob report
termSalesJob report
jfScanJob report
operatorSalesJob report
operatorSpecialSalesJob report
syncTopSaleByDayJob report
operatorDataJob report
npBusiSpecWeekMonthReportJob report
analyseTopSaleDayJob report
analyseTopSaleWeekAndMonthJob report
clearScreenCacheJob report
commStockReportJob report
costDetailJob report
incomeDetailJob report
bigScreenIncomeAndCostJob report
termSaleGatherDayJob report
termSalesGatherJob report
mobileSaleGatherDayJob report
mobileTermSalesGatherJob report
incomeAndCostReportJob report
businessInfoMonitorJob report
ticketBigDataJob report
activityStatisticsByDayJob report
detectFtpFileJob report
electronicKafkaInfoJob report
storePerformmanceJob report
bdElectronicKafkaDataJob report
testJob service
reportJob service
topSessionJob service
topGetStoresJob service
topItemsGetJob service
topGoodsDetailJob service
topTradeDownloadJob service
topUserPermitJob service
topMsgConsumerJob service
bdStoreChlJob service
bdSmsPushJob service
smsFeedbackJob service
targetUserJob service
propertyInfoJob service
storeAndAdminAreaUploadJob service
newTargetUserJob service
blackAndWhiteListSynJob service
areaCacheJob sysman
departCacheJob sysman
departJianPinJob sysman
allAreaCacheJob sysman
staffCacheJob sysman
areaSyncJob sysman
allFuncrightCacheJob sysman
synDepartJob sysman
originDepartCacheJob sysman
allAdminAreaCacheJob sysman
adminAreaCacheJob sysman
testAJob sysman
testBJob sysman
storeCacheJob sysman
备注:就想要第一列是对齐的,同时第二列也是对齐的.
2.使用awk进行格式化(首先将上面的内容粘贴到linux一个文件中)
[root@testvm ~]# cat abc.txt | awk '{printf "%-30s%-15s\n",$1,$2}' #%-30s表示输出字符串,宽度30位,左对齐.%-15s用来指定第二列的,左对齐,宽度15.两个百分号之间可以没有空格.使用\n对每一行的输出加上换行符
job_name job_group
syncCommStockJob dataSync
syncStoreChnlJob dataSync
syncOrderJob dataSync
syncReportStoreJob dataSync
hdfsScanJob report
orderSaleDailyJob report
jdzmdOrdersJob report
jdCanJob report
tbTermSalesJob report
ess3GTermSalesJob report
npBusiDayReportJob report
npBusiWeekMonthReportJob report
snOrdersScreenJob report
jdzmdOrderScreenJob report
jjTermSalesJob report
termSalesJob report
jfScanJob report
operatorSalesJob report
operatorSpecialSalesJob report
syncTopSaleByDayJob report
operatorDataJob report
npBusiSpecWeekMonthReportJob report
analyseTopSaleDayJob report
analyseTopSaleWeekAndMonthJob report
clearScreenCacheJob report
commStockReportJob report
costDetailJob report
incomeDetailJob report
bigScreenIncomeAndCostJob report
termSaleGatherDayJob report
termSalesGatherJob report
mobileSaleGatherDayJob report
mobileTermSalesGatherJob report
incomeAndCostReportJob report
businessInfoMonitorJob report
ticketBigDataJob report
activityStatisticsByDayJob report
detectFtpFileJob report
electronicKafkaInfoJob report
storePerformmanceJob report
bdElectronicKafkaDataJob report
testJob service
reportJob service
topSessionJob service
topGetStoresJob service
topItemsGetJob service
topGoodsDetailJob service
topTradeDownloadJob service
topUserPermitJob service
topMsgConsumerJob service
bdStoreChlJob service
bdSmsPushJob service
smsFeedbackJob service
targetUserJob service
propertyInfoJob service
storeAndAdminAreaUploadJob service
newTargetUserJob service
blackAndWhiteListSynJob service
areaCacheJob sysman
departCacheJob sysman
departJianPinJob sysman
allAreaCacheJob sysman
staffCacheJob sysman
areaSyncJob sysman
allFuncrightCacheJob sysman
synDepartJob sysman
originDepartCacheJob sysman
allAdminAreaCacheJob sysman
adminAreaCacheJob sysman
testAJob sysman
testBJob sysman
storeCacheJob sysman
备注:使用printf进行输出第一列和第二列.然后使用%s表示输出字符串,并且通过负号(-),数字表示的是左对齐输出.这样就达到了对格式进行整理.
文档创建时间:2018年7月12日10:59:29
linux中通过awk进行文本的对齐格式化处理?awk printf左对齐?的更多相关文章
- wordpress 后台富文本编辑器,添加图片发现无法左对齐,样式出现混乱
如上图所示,无法左对齐,但是左对齐的按钮全部是正确的,最后一点点排除,发现是因为这个词的影响,去掉就好了,原因不明,可能是这个词被当做某个方法执行了
- bootstrap 轮播图带缩列图两端对齐,并自动换行然后左对齐!
禁止自动轮播 data-interval="false" 完整代码如下: 1 <!DOCTYPE html> 2 <html> 3 4 <head&g ...
- Linux中图形界面和文本模式相互切换
1.默认开机进入文本模式 如果想让开机自动进纯文本模式, 修改/etc/inittab 找到其中的 id:5:initdefault: 这行指示启动时的运行级是5,也就是图形模式 改成3就是文本模式了 ...
- css 单行文本居中显示,多行文本左对齐
父级元素 text-align:center; 自级元素 text-align:left; display:inline-block;
- linux中awk命令(最全面秒懂)
目录 一:linux中awk命令 1.awk命令简介 2.awk作用 3.awk的语法格式 4.解析awk使用方法 5.参数 6.awk的生命周期 二:awk中的预定义变量 三:awk运行处理规则的执 ...
- linux中awk命令详解(最全面秒懂)
一:linux中awk命令 1.awk命令简介 AWK 是一种处理文本文件的语言,是一个强大的文本分析工具. 之所以叫 AWK 是因为其取了三位创始人 Alfred Aho,Peter Weinber ...
- linux(六)之文本操作
接下来我们一起来看一下再linux中怎么去对文本进行操作的 一.文本文件 既然要操作文本,所以我们要对文本有一个了解,那什么是文本文件呢. 文本文件是一种由若干行字符构成的计算机文件.文本文件存在于计 ...
- linux中vi编辑器的使用
vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本 编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的任 何版本,vi编辑器是完 ...
- iOS上让按钮文本左对齐问题
一,问题分析 1.在做历史记录视图的时候,由于让键盘退出后才能触发表格的 didselect 那个代理方法,也就是得点两下才触发,而表格中的按钮点一下就可以立即响应. 2.于是我就有了用按钮事件代替 ...
随机推荐
- r语言笔记 jn
get_range <- function(data_name , row_name){ library(stringr) load(data_name) data_str <- str_ ...
- 【转】Smartphone--Android真机管理平台
背景 最近在工作中发现几个问题: 作为测试人员,在做产品兼容性测试时,发现手上的测试设备总是不够用,但是可能其他同事的设备在闲置着: 作为Android和H5开发人员,如果测试同事发现一个兼容性的bu ...
- 【转】web前端到底怎么学?干货资料!
一般据我经验,在喜欢并且决定和她恋爱之前,我都会做一下充分准备和调查,有必要了解和研究清楚 ‘她’ 的几个特性和习惯 web前端的基本工作职责 和基础技能(要清楚) web前端的分类和门派(简要概述, ...
- Sword protobuf学习四
#include <iostream> #include <string> #include <sys/types.h> /* See NOTES */ #incl ...
- FaceAlignment blog
https://blog.csdn.net/app_12062011/article/category/7574425 https://www.jianshu.com/p/e4b9317a817f
- 【Python】windows电脑 python3.6安装lxml库
1.下载lxml的wheel文件 https://download.lfd.uci.edu/pythonlibs/t5yhk4lc/lxml-4.2.1-cp36-cp36m-win32.whl 其他 ...
- 【Python】python3实现网页爬虫下载图片
import re import urllib.request # ------ 获取网页源代码的方法 --- def getHtml(url): page = urllib.request.urlo ...
- 近期小结 之 Servlet规范及HTTP
最近认真看了下Servlet 3.1的规范,略有收获,如下: 如果客户端不指定编码,Servlet容器必须使用ISO-8859-1编码来处理,且不能添加相应编码信息. Servlet 3 可以手动开启 ...
- Spring Data Commons 官方文档学习
Spring Data Commons 官方文档学习 -by LarryZeal Version 1.12.6.Release, 2017-07-27 为知笔记版本在这里,带格式. Table o ...
- C# ?? 运算符是什么?
?? 运算符定义在将可空类型分配给非可空类型时返回的默认值. int? c = null; //若 c 为 null,则 d 为 -1,否则把 c 值赋予 dint d = c ?? -1;