- 论坛徽章:
- 145
|
回复 1# irockey
issue 1: single quote
$ awk 'BEGIN{RS="[,.!?-'" ]"}{w[$0]+=1}END{for(a in w) print a"\t"w[a]}' file.txt
bash: syntax error near unexpected token `('
solution: change it to hexadecimal of ascii code
$ ascii "Single Quote" # or $ ascii "'"
ASCII 2/7 is decimal 039, hex 27, octal 047, bits 00100111: prints as `''
------------------------------------------------------------------------
issue 2: double quote
Single Quote change to \x27
$ awk 'BEGIN{RS="[,.!?-\x27" ]"}{w[$0]+=1}END{for(a in w) print a"\t"w[a]}' file.txt
awk: cmd. line:1: BEGIN{RS="[,.!?-\x27" "}{w[$0]+=1}END{for(a in w) print a"\t"w[a]}
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: BEGIN{RS="[,.!?-\x27" ]"}{w[$0]+=1}END{for(a in w) print a"\t"w[a]}
awk: cmd. line:1: ^ backslash not last character on line
solution: change it to \" or \x22 in double quote string
------------------------------------------------------------------------
issue 3: Hyphen issue
$ awk 'BEGIN{RS="[,.!?-\x27\" ]"}{w[$0]+=1}END{for(a in w) print a"\t"w[a]}' file.txt
awk: cmd. line:1: fatal: Invalid range end: /[,.!?-'" ]/
[1-3 will be => 1, 2, 3 or 4
[-13] will be => -, 1 or 3
[13-] will be => 1, 3 or -
Note: Hyphen must be in head or tail
Solution: place it to head or tail between [ and ]
$ awk 'BEGIN{RS="[,.!?\x27\" -]"}{w[$0]+=1}END{for(a in w) print a"\t"w[a]}' file.txt
...
|
|