123
123

Reputation: 8951

Bash error - cut: the delimiter must be a single character (trying to use "/")

I'm trying to use a forward slash as a delimiter but I'm getting the error:

cut: the delimiter must be a single character

This is my command:

cat index.html |grep “href=“ |cut -d”/“ -f3 |more

Upvotes: 1

Views: 4196

Answers (1)

Rob Starling
Rob Starling

Reputation: 3908

i suspect you're pasting high-ascii (fancy unicode) double-quotes there.

compare:

$ echo cut -d”/“ | hexdump -C
00000000  63 75 74 20 2d 64 e2 80  9d 2f e2 80 9c 0a        |cut -d.../....|
0000000e

$ echo cut -d"/" | hexdump -C
00000000  63 75 74 20 2d 64 2f 0a                           |cut -d/.|
00000008

2f is the (forward) slash, which is all you want cut to see for its -d argument. Note that in the second expression, bash doesn't send the actual double quotes to the command at all, which is your goal.

e2 80 9d 2f e2 80 9c is e2 80 9d + 2f + e2 80 9c. e2 80 9d (11100010 10000000 10011101 in binary) is UTF-8 for U+201d and e2 80 9c is UTF-8 for U+201c, which are right double quotation mark and left double quotation mark, respectively. It's interesting that your paste resulted in having them "inside-out" -- that is //x\\ rather than \\x//.

The low-ascii double-quote that bash does strip is 22 (hex, or 34 in decimal), which in unicode parlance is U+0022 (quotation mark).

I'd highly recommend reading the "QUOTING" section of Bash's manual page (man bash and search for QUOTING (type /QUOTING + Enter), then scroll with up and down arrow keys, and q to quit)

Upvotes: 3

Related Questions