So, I have some data that looks like this:
19/10/2020 05:57:08.200, 362173.64, 4498564.26, 10.000, 10.000, 0.000, 0, 3.2,
19/10/2020 05:57:08.270, 362173.64, 4498564.38, 10.000, 10.000, 0.000, 0, 3.2,
19/10/2020 05:57:08.340, 362173.64, 4498564.49, 10.000, 10.000, 0.000, 0, 3.2,
19/10/2020 05:57:08.410, 362173.64, 4498564.61, 10.000, 10.000, 0.000, 0, 3.7,
19/10/2020 05:57:08.470, 362173.64, 4498564.72, 10.000, 10.000, 0.000, 0, 2.8,
I need to sort the data by time stamp. Under linux, I would run this data through awk to pick apart the date and time to look like this:
2020 05 10 19 57 08.200 362173.64 4498564.26 10.000 10.000 0.000 0 3.2
2020 05 10 19 57 08.270 362173.64 4498564.38 10.000 10.000 0.000 0 3.2
2020 05 10 19 57 08.340 362173.64 4498564.49 10.000 10.000 0.000 0 3.2
Using a command like this:
awk -F'[/:,]' '{print $3,$2,$1,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14}'
Then run that through sort and back through awk to put the columns back in the correct order.
awk -F'[/:,]' '{print $3,$2,$1,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14}' | sort |
awk -F' ' '{print $3"/"$2"/"$1,$4":"$5":"$6","$7","$8","$9","$10","$11","$12","$13","$14}'
Is there a better way to do this in powershell, or at least a way to do the same thing? I have a powershell script that very clumsily does something similar, but somewhere in the process I lose the newlines...
$nav = (gc $navfile | %{$_ -replace ", ",","} | %{$_ -replace " ",""} | %{"$($_.Split('[/,:]')[2,1,0,3,4,5,6,7,8,9,10,11,12,13,14])"} | sort-object | %{"$($_.Split(' ')[2,1,0,3,4,5,6,7,8,9,10,11,12,13,14])"} )
[regex]$sorted = " "
$one = $sorted.replace($nav, "/", 2)
$two = $sorted.replace($one, "!", 1)
$three = $sorted.replace($two, ":", 2)
$four = $three | %{$_ -replace " ",","}
$five = $four | %{$_ -replace "!"," "}
$six = $five | %{$_ -replace ",,","`n"}
echo $six
Any help would be greatly appreciated.
sortfunctionality so - why not just do it all in 1 call to awk? If you edit your question to show the expected output then we can help you - I tried running theawk | sort | awkpipeline you provided on the data you posted but the output didn't make sense so I assume that script or the sample input isn't actually correct. Isn't your posted sample input already sorted by timestamp? If so, that's not useful to test a sorting function.