-1

I'm trying to execute the following command via Go:

cut -f1 -d $'\t' fileName | sort | uniq -d

My code:

log.Printf("%s %s %s %s %s %s", "cut", "-f1", "-d ", "$'\\t'", fileName, " | sort | uniq -d")

r, e = exec.Command("cut", "-f1", "-d", "$'\\t'", sortedFile, " | sort | uniq -d").CombinedOutput()

log.Printf("o/p:%d", string(r))

This gives a bad delimiter error but the command printed runs on command line

Log snippet:

2020/09/17 13:27:13 cut -f1 -d  $'\t' /Users/samalhot/Documents/test_sorted.txt  | sort | uniq -d
2020/09/17 13:27:13 o/p:%!d(string=cut: bad delimiter
)

What am I doing wrong?

  • 2
    `$'\t'` ist shell syntax. In Go simply write `"\t"`. For pipes see https://stackoverflow.com/questions/10781516/how-to-pipe-several-commands-in-go. – Peter Sep 17 '20 at 17:34

1 Answers1

0

Thanks, that worked!

log.Printf("%s %s %s %s %s %s", "cut", "-f1", "-d ", "\t", sortedFile, " | sort | uniq -d")

r, e = exec.Command("cut", "-f1", "-d", "\t", sortedFile, " | sort | uniq -d").Output()

log.Printf("o/p:%d", string(r))