如何使用/作为字段分隔符值复制到行尾?使用?作为分隔符?
我有一个类似这样的文件:
/folder/subfolder1/user1/1234/file.jpg,2014-11-24 11:49:55.6590447890 +0200
/folder/subfolder1/user2/ddaa/file.jpg,2014-11-24 11:49:55.6590447890 +0200
/folder/subfolder1/user2/sssffd/file.jpg,2014-11-24 11:43:03.6438296240 +0200
/folder/subfolder1/user3/882ssa/file.jpg,2014-11-24 11:43:00.6918628210 +0200
我需要的输出是:
/folder/subfolder1/user1/1234/file.jpg,2014-11-24 11:49:55.6590447890 +0200,1234,1234 2014-11-24 11:49:55.6590447890 +0200,user1
/folder/subfolder1/user2/ddaa/file.jpg,2014-11-24 11:49:55.6590447890 +0200,ddaa,ddaa 2014-11-24 11:49:55.6590447890 +0200,user2
/folder/subfolder1/user2/sssffd/file.jpg,2014-11-24 11:43:03.6438296240 +0200,sssffd,sssffd 2014-11-24 11:49:55.6590447890 +0200,user2
/folder/subfolder1/user3/882ssa/file.jpg,2014-11-24 11:43:00.6918628210 +0200,882ssa,882ssa 2014-11-24 11:49:55.6590447890 +0200,user3
所以我需要将该行的某些部分复制到它的末尾,并将几个字段组合在一起。
答案 0 :(得分:1)
怎么样
$ awk -F[/,] '{$0=$0","$5","$5" "$7","$4}1' input
/folder/subfolder1/user1/1234/file.jpg,2014-11-24 11:49:55.6590447890 +0200,1234,1234 2014-11-24 11:49:55.6590447890 +0200,user1
/folder/subfolder1/user2/ddaa/file.jpg,2014-11-24 11:49:55.6590447890 +0200,ddaa,ddaa 2014-11-24 11:49:55.6590447890 +0200,user2
/folder/subfolder1/user2/sssffd/file.jpg,2014-11-24 11:43:03.6438296240 +0200,sssffd,sssffd 2014-11-24 11:43:03.6438296240 +0200,user2
/folder/subfolder1/user3/882ssa/file.jpg,2014-11-24 11:43:00.6918628210 +0200,882ssa,882ssa 2014-11-24 11:43:00.6918628210 +0200,user3