linux - Bash column altering -
i have data in columns, data confusing column numbers making bash opperations confusing, data below working (however there on 1 million lines of). interested in numbers in 8th , 9th column:
2014-05-10 08:47:57.373 3600.633 udp 114.31.255.90:57844 -> 42.209.2.47:52436 1.3 m 1.8 g 1 2014-05-10 09:50:39.609 3601.385 udp 114.31.255.90:57844 -> 60.120.101.149:47403 1.0 m 1.5 g 1 2014-05-10 10:00:14.064 3607.106 udp 114.31.255.90:57844 -> 46.83.205.250:32307 2.0 m 3.0 g 1 2014-05-10 10:03:04.263 3644.192 udp 114.31.255.90:57844 -> 1.32.33.64:10933 987743 1.4 g 1 2014-05-10 11:07:16.247 546.764 tcp 105.51.244.36:80 -> 114.31.255.222:55580 797919 1.2 g 1 2014-05-10 10:46:15.190 2332.334 udp 114.31.255.90:57844 -> 43.95.27.215:53394 1.1 m 1.7 g 1 2014-05-10 11:00:49.005 1458.456 udp 114.31.255.90:57844 -> 39.150.172.138:39326 1.2 m 1.7 g 1 2014-05-09 23:53:03.625 56.271 icmp 61.114.116.140:3 -> 114.31.255.88:0.3 2 318 1 2014-05-09 23:53:59.833 0.000 udp 114.31.255.88:15360 -> 24.56.237.230:24752 1 131 1 2014-05-09 23:53:59.835 0.000 udp 114.31.255.88:15360 -> 154.115.89.25:28904 1 131 1 2014-05-09 23:53:59.767 0.174 tcp 105.51.244.40:80 -> 114.31.255.41:28520 13 6675 1 2014-05-09 23:53:59.409 0.000 udp 114.31.255.70:53 -> 114.31.255.244:54604 1 536 1 2014-05-09 23:53:59.621 0.333 tcp 105.51.244.40:80 -> 114.31.255.41:28519 16 7034 1
i use tr make data processing easier turning spaces one:
tr -s ' '
which makes using (below) easier:
cut -f [column number(s)] -d ' '
however when value has g or m confuses colum numbering. change example:
2014-05-10 11:00:49.005 1458.456 udp 114.31.255.90:57844 -> 39.150.172.138:39326 1.2 m 1.7 g 1
to
2014-05-10 11:00:49.005 1458.456 udp 114.31.255.90:57844 -> 39.150.172.138:39326 1.2m 1.7g 1
i have tried
tr ' g ' 'g ' tr ' m ' 'm '
also using [:space:] in different configurations have not succeeded.
tr
doesn't work sed
translates character characters. use sed
this:
sed 's/ \([mg] \)/\1/g'
explanation:
/ \([mg] \)/ # match space followed letter m or g , followed space. # capture matched letter in matched group #1 \1 # replace back-reference #1
Comments
Post a Comment