问题
I have a file:
CreateSec,explorer.exe,\\WINDOWS\\system32\\verclsid.exe,SUCCESS
I want to print "$2"
Example 1
It works well:
$ awk -F '\\\\\\\\' '{print $2}' file
WINDOWS
Example 2
It works well:
$ awk -F '\\\\'+ '{print $2}' file
WINDOWS
Example 3
Does not print.
$ awk -F "\\\\\\\\" '{print $2}' file
.
Example 4
So it works well:
$ echo "CreateSec,explorer.exe,\\WINDOWS\\system32\\verclsid.exe,SUCCESS" | awk -F '\' '{print $2}'
WINDOWS
----------------------------------------------------------------------------------
$ echo "CreateSec,explorer.exe,\\WINDOWS\\system32\\verclsid.exe,SUCCESS" | awk -F "\\" '{print $2}'
WINDOWS
Questions:
- Why 3 example does not work?
- How to properly save 3 example?
What is the difference between?:
a)
awk -F '\\\\\\\\'b)
awk -F "\\\\\\\\"
Thank you for the explanation.
回答1:
Regarding (3) — four backslashes is the difference:
- Inside single quotes, there are no metacharacters, so the shell passes 8 backslashes to
awk. - Inside double quotes, the backslash escapes the following character, so the shell passes 4 backslashes to
awk.
来源:https://stackoverflow.com/questions/13609479/awk-field-separator-behavior