【问题标题】:Splitting a File with multiple header line拆分具有多个标题行的文件
【发布时间】:2022-09-27 22:27:09
【问题描述】:

我正在尝试使用以下代码拆分具有多个标题行的大文件。虽然在工作;但在拆分文件的标题后引入了一个空行。如何摆脱空行?

/^@/ {
    hdr = hdr $0 ORS
    next
}
split($NF, a, \":\")
!seen[a[3]]++{
    out = a[3] \"_txt\"
    print hdr > out
}
{out = a[3] \"_txt\"
 print >> out 
 close(f)}

    标签: awk


    【解决方案1】:

    由于您每次都在hdr 字段中添加ORS,然后在使用print hdr > out 时,它会在最后添加另一个换行符。

    你应该像这样使用printf:

    printf "%s", hdr > out
    

    【讨论】:

      猜你喜欢
      • 2013-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      相关资源
      最近更新 更多