这是Feed文件
dfscmd /map "\\SERVER24\dfs\shared\can\Group Pension\Quality Assurance Auditors" "\\serverfile16\bugp-qaaud$" ""
dfscmd /map "\\SERVER24\dfs\userhome\serverfile52_d" "\\serverfile52\userhome_d" ""
dfscmd /map "\\SERVER24\dfs\shared\can\Wealth Management\WM CSC Stats - Support Team, CRT Team & CSR Performance" "\\serverfile48\bucan-WM_CSC_Support_&_CRT_Team_Stats" ""
使用此行
gawk -v FS=""" "{print $2 \";\" $4 }" a.txt
我可以打印,但无法保存输出,
C:\>gawk -v FS=""" "{print $2 \";\" $4 }" a.txt >b.txt
\\SERVER24\dfs\shared\can\Group Pension\Quality Assurance Auditors;\\serverfile16\bugp-qaaud$
\\SERVER24\dfs\userhome\serverfile52_d;\\serverfile52\userhome_d
\\SERVER24\dfs\shared\can\Wealth Management\WM CSC Stats - Support Team, CRT Team & CSR Performance;\\serverfile48\bucan- WM_CSC_Support_&_CRT_Team_Stats
gawk: (FILENAME=a.txt FNR=3) fatal: cannot open file `>b.txt' for reading (Invalid argument)
答案 0 :(得分:2)
单引号应始终用于围绕awk
的大括号。这会更好:
gawk -v FS=\" '{ print $2 ";" $4 }' a.txt > b.txt
b.txt
的内容:
\\SERVER24\dfs\shared\can\Group Pension\Quality Assurance Auditors;\\serverfile16\bugp-qaaud$
\\SERVER24\dfs\userhome\serverfile52_d;\\serverfile52\userhome_d
\\SERVER24\dfs\shared\can\Wealth Management\WM CSC Stats - Support Team, CRT Team & CSR Performance;\\serverfile48\bucan-WM_CSC_Support_&_CRT_Team_Stats
<强> 编辑: 强>
如果您正在使用Windows,您可能还想考虑运行这样的脚本:
gawk -f script.awk a.txt > b.txt
script.awk
的内容:
BEGIN { FS="\"" }
{ print $2 ";" $4 }
这样可以避免在表达式中包含引号并生成所需的结果。 HTH。
答案 1 :(得分:0)
gawk -v FS=""" "{print $2 \";\" $4 }" a.txt ">b.txt