0

这是提要文件,

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)
4

2 回答 2

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。

于 2012-11-07T00:16:24.453 回答
0
gawk -v FS=""" "{print $2 \";\" $4 }" a.txt   ">b.txt
于 2012-11-07T00:16:27.293 回答