需求描述:

  今天在对一个从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左对齐?的更多相关文章

  1. wordpress 后台富文本编辑器,添加图片发现无法左对齐,样式出现混乱

    如上图所示,无法左对齐,但是左对齐的按钮全部是正确的,最后一点点排除,发现是因为这个词的影响,去掉就好了,原因不明,可能是这个词被当做某个方法执行了

  2. bootstrap 轮播图带缩列图两端对齐,并自动换行然后左对齐!

    禁止自动轮播 data-interval="false" 完整代码如下: 1 <!DOCTYPE html> 2 <html> 3 4 <head&g ...

  3. Linux中图形界面和文本模式相互切换

    1.默认开机进入文本模式 如果想让开机自动进纯文本模式, 修改/etc/inittab 找到其中的 id:5:initdefault: 这行指示启动时的运行级是5,也就是图形模式 改成3就是文本模式了 ...

  4. css 单行文本居中显示,多行文本左对齐

    父级元素 text-align:center; 自级元素 text-align:left; display:inline-block;

  5. linux中awk命令(最全面秒懂)

    目录 一:linux中awk命令 1.awk命令简介 2.awk作用 3.awk的语法格式 4.解析awk使用方法 5.参数 6.awk的生命周期 二:awk中的预定义变量 三:awk运行处理规则的执 ...

  6. linux中awk命令详解(最全面秒懂)

    一:linux中awk命令 1.awk命令简介 AWK 是一种处理文本文件的语言,是一个强大的文本分析工具. 之所以叫 AWK 是因为其取了三位创始人 Alfred Aho,Peter Weinber ...

  7. linux(六)之文本操作

    接下来我们一起来看一下再linux中怎么去对文本进行操作的 一.文本文件 既然要操作文本,所以我们要对文本有一个了解,那什么是文本文件呢. 文本文件是一种由若干行字符构成的计算机文件.文本文件存在于计 ...

  8. linux中vi编辑器的使用

    vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本 编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的任 何版本,vi编辑器是完 ...

  9. iOS上让按钮文本左对齐问题

    一,问题分析 1.在做历史记录视图的时候,由于让键盘退出后才能触发表格的 didselect 那个代理方法,也就是得点两下才触发,而表格中的按钮点一下就可以立即响应. 2.于是我就有了用按钮事件代替 ...

随机推荐

  1. C语言 · 十进制数转八进制数

    算法训练 十进制数转八进制数   时间限制:1.0s   内存限制:512.0MB      编写函数把一个十进制数输出其对应的八进制数. 样例输入 9274 样例输出 22072   #includ ...

  2. git .gitignore 文件不起作用

    .gitignore 不起作用的原因是因为 git 有以前文件缓存,只要清理一次缓存即可 git rm -r --cached . // 然后再进行 git git add . git commit

  3. LeetCode之Decode Ways

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  4. 1 php protocolbuffers安装

    安装工具 yum install autoconf yum install libtool 安装protoc编译器 # cd /root/soft/protobuf- autogen.sh : if ...

  5. JQuery控制radio选中和不选中方法总结

    一.设置选中方法 代码如下: $("input[name='名字']").get(0).checked=true; $("input[name='名字']"). ...

  6. 数据框排序 data.frame order

    # sorting examples using the mtcars datasetattach(mtcars) # sort by mpgnewdata <- mtcars[order(mp ...

  7. r语言笔记 jn

    get_range <- function(data_name , row_name){ library(stringr) load(data_name) data_str <- str_ ...

  8. mxnet卷积计算

    #coding:utf-8 ''' 卷积计算 ''' import mxnet as mx from mxnet.gluon import nn from mxnet import ndarray a ...

  9. VUE系列二:vue基础

    一.组件嵌套 1. 新建一个组件Users.vue <template> <div class="users"> <ul> <li v-f ...

  10. Xianfeng轻量级Java中间件平台:用户管理

    用户管理:简单地说,就是管理系统用户的账号信息.在典型的业务系统中,用户管理往往不包含用户隶属组织机构相关属性(比如部门.岗位等)的维护,而是由组织机构管理专门去维护.因此在用户管理的功能中,主要就维 ...