zoukankan      html  css  js  c++  java
  • 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
    ",$1,$2}'               #%-30s表示输出字符串,宽度30位,左对齐.%-15s用来指定第二列的,左对齐,宽度15.两个百分号之间可以没有空格.使用
    对每一行的输出加上换行符
    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

  • 相关阅读:
    Delphi开发组件
    WPF界面开发.NET环境该如何配置?不知道VS版本支持的看过来
    Map控件是如何支持矢量切片的?DevExpress WPF界面开发者必看!
    数据可视化新方式,SankeyDiagramControl类的使用你不能错过!(Part 1)
    VCL界面开发工具!DevExpress VCL v20.1.7全新出发
    如何使用自动生成的序列创建3D图表?DevExpress WPF有妙招(Part 3)
    如何使用Kendo UI在Vue.js中轻松构建UI组件?
    php结合redis实现高并发下的抢购、秒杀功能
    书写高质量SQL的30条建议
    php 通过openresty搭载负载均衡
  • 原文地址:https://www.cnblogs.com/chuanzhang053/p/9298409.html
Copyright © 2011-2022 走看看