需求描述:

  今天在对一个从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. Scrum卡片层次图

    对照国内的项目管理软件禅道,可以好好感受一下,何为Scrum. 看板则一定要是实物,才有感觉.

  2. MVC源码学习之AuthorizeAttribute

    常见的Controller定义方式: public class HomeController : Controller { public ActionResult Index() { return V ...

  3. webbrowser取页面验证码

    碰到一个无比坑爹,外加蛋疼乳酸的问题.从昨天晚上发现bug,到今天下午解决问题,搞了大半天的时间.光是找问题就花了半天,解决问题的方法简单,但是方案的形成也是无比纠结的过程. 背景:webbrowse ...

  4. metrics 开发监控实现jdbc

    Metrics 主要有五大基本组件1:Counter  记录执行次数2:Gauge  获取某个值3:Meter  用来计算事件的速率4:Histogram  可以为数据流提供统计数据. 除了最大值,最 ...

  5. Android开发,使用背景图(xml drawable)为view 设置边框

    Android 开发中,遇到需要设置边框的情景,使用背景图来实现,代码如下: <layer-list xmlns:android="http://schemas.android.com ...

  6. .net 4中使用 dynamic,将json字符串转成对象的 万能方法。

    在.net 4中增加了对弱类型的支持.为和弱类型的对象进行数据交换提供了方法.我们常常会遇到将json字符串转成对象的情景,虽然可以使用 JavaScriptSerializer 或者 DataCon ...

  7. ie6 无法显示网页 已终止操作

    已终止操作原因: 在文件加载完成之前执行了dom操作,如appendChild, innerHTML等 解决办法: ready后再执行

  8. How get a String Width in Libgdx?

    http://stackoverflow.com/questions/16600547/how-get-a-string-width-in-libgdx

  9. @Resource、@Autowired跟default-autowire区别联系

    @Resource.@Autowired和default-autowire区别联系 今天看了一工程,里面既有default-autowire,又有@Autowired,还有@Resource.我就不明 ...

  10. C#中二进制和流之间的各种相互转换

    一. 二进制转换成图片间的转换 1 2 3 4 5 MemoryStream ms = new MemoryStream(bytes); ms.Position = 0; Image img = Im ...