I want to cut everything with a delimiter ":" The input file is in the following format:
data1:data2
data11:data22
...
I have a linux command
cat merged.txt | cut -f1 -d ":" > output.txt
On mac terminal it gives an error:
cut: stdin: Illegal byte sequence
what is the correct way to do it on a mac terminal?
Your input file (merged.txt) probably contains bytes/byte sequences that are not valid in your current locale. For example, your locale might specify UTF-8 character encoding, but the file be in some other encoding and cannot be parsed as valid UTF-8. If this is the problem, you can work around it by telling
tr
to assume the "C" locale, which basically tells it to process the input as a stream of bytes without paying attention to encoding.BTW,
cat file |
is what's commonly referred to as a Useless Use of Cat (UUOC) -- you can just use a standard input redirect< file
instead, which cleaner and more efficient. Thus, my version of your command would be:Note that since the
LC_ALL=C
assignment is a prefix to thetr
command, it only applies to that one command and won't mess up other operations that should assume UTF-8 (or whatever your normal locale is).