Михаил обнови решението на 31.10.2015 11:53 (преди над 2 години)
+package main
+
+import "strings"
+
+func ExtractColumn(logContents string, column uint8) string {
+ rows := strings.SplitAfter(logContents, "\n")
+ result := ""
+ for _, row := range rows {
+ columns := strings.SplitN(row, " ", 4)
+ if len(columns) < 4 {
+ continue
+ }
+
+ var toAppend string
+ switch column {
+ case 0:
+ toAppend = strings.Join(columns[:2], " ") + "\n"
+ case 1:
+ toAppend = columns[2] + "\n"
+ case 2:
+ toAppend = columns[3]
+ }
+ result = strings.Join([]string{result, toAppend}, "")
+ }
+
+ if len(result) > 0 && result[len(result)-1] != '\n' {
+ result = strings.Join([]string{result, "\n"}, "")
+ }
+ return result
+}