awk copy field data to new field

How do I copy using / as field delimiter values to the end of the line using , as the delimiter?

I have a file that has something like this in it:

/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

and what I need as an output would be:

/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

So I need to copy some parts of the line to the end of it and also put together a few fields as one.

Upvotes: 0

Views: 158

Answers (1)

nu11p01n73R
nu11p01n73R

Reputation: 26667

How about

$ 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

Upvotes: 1

Related Questions