我有一个来自重复数据删除工具 (rmlint) 的 csv 文件。我想使用 awk 在给定字段(如校验和)共享相同值的行组之后添加潜水线。
文件:
type,path,size,checksum
emptydir,"/home/user/tree2/b",0,00000000000000000000000000000000
duplicate_dir,"/home/user/test/b",4,f8772f6fda08bbc826543334663d6f13
duplicate_dir,"/home/user/test/a",4,f8772f6fda08bbc826543334663d6f13
duplicate_dir,"/home/user/tree/b",8,62202a79add28a72209b41b6c8f43400
duplicate_dir,"/home/user/tree/a",8,62202a79add28a72209b41b6c8f43400
duplicate_dir,"/home/user/tree2/a",4,311095bc5669453990cd205b647a1a00
期望的输出:
type,path,size,checksum
------------------------
emptydir,"/home/user/tree2/b",0,00000000000000000000000000000000
------------------------
duplicate_dir,"/home/user/test/b",4,f8772f6fda08bbc826543334663d6f13
duplicate_dir,"/home/user/test/a",4,f8772f6fda08bbc826543334663d6f13
------------------------
duplicate_dir,"/home/user/tree/b",8,62202a79add28a72209b41b6c8f43400
duplicate_dir,"/home/user/tree/a",8,62202a79add28a72209b41b6c8f43400
------------------------
duplicate_dir,"/home/user/tree2/a",4,311095bc5669453990cd205b647a1a00
我怎么能用 awk 做这件事呢?
存储先前的值,并在当前值不匹配时输出一行:
(
$NF
是最后一个字段,调整以适应。)破折号的数量可以更容易地定制如下:
或者,使用 GNU AWK:
将“20”更改为任何合适的值。
这是另一个版本,您可以在其中选择分隔线的长度(本例中为 20):