我正在尝试调用一个包含百分号的变量,但是当我这样做时,我收到以下错误。即使只是试图创建它,它也会出错。当我排除它时,我的脚本工作正常,但我希望它在第3个字段中打印此变量值。
awk -v postutil="$postutil"
错误的部分输出:
awk: cmd. line:2: postutil=66%
awk: cmd. line:2: ^ unexpected newline or end of string
awk: cmd. line:2: postutil=68%
awk: cmd. line:2: ^ unexpected newline or end of string
awk: cmd. line:2: postutil=63%
awk: cmd. line:2: ^ unexpected newline or end of string
awk: cmd. line:2: postutil=38%
awk: cmd. line:2: ^ unexpected newline or end of string
awk: cmd. line:2: postutil=30%
awk: cmd. line:2: ^ unexpected newline or end of string
awk: cmd. line:2: postutil=29%
awk: cmd. line:2: ^ unexpected newline or end of string
awk: cmd. line:2: postutil=91%
awk: cmd. line:2: ^ unexpected newline or end of string
awk: cmd. line:2: postutil=0%
awk: cmd. line:2: ^ unexpected newline or end of string
awk: cmd. line:2: postutil=0%
awk: cmd. line:2: ^ unexpected newline or end of string
脚本:
while IFS=$'\t' read -r hostname interface preutil postutil criticality; do
awk -v hostname="$hostname" -v interface="$interface" -v postutil="$postutil" '$0~ hostname "\t" interface{print hostname, interface, postutil, $0}' OFS='\t' temp/post_lsp_interfaces_02.txt
done < temp/comparison_interfaces_high_med.txt
部分post_lsp_interfaces_02.txt
ASHBBPRJ01-CHNDDSRJ01-BE ASHBBPRJ01 ae2.0 ASHBBBRJ02 ae9.0 MCDLBBRJ01 ae9.0 CHNDBBRJ01 ae0.0 CHNDDSRJ01 3740.81
ASHBBPRJ01-DUKEDSRJ02-BE ASHBBPRJ01 ae1.0 ASHBBBRJ01 ae10.0 DUKEBBRJ02 ae6.0 DUKEDSRJ02 8182.02
ASHBBPRJ01-HMRDRCRJ01-BE ASHBBPRJ01 ae2.0 ASHBBBRJ02 ae11.0 MRFDBBRJ02 ae0.0 MRFDBBRJ01 ae4.0 NRFKBBRJ01 ae0.0 NRFKDSRJ01 ae17.0 HMRDRCRJ01 4444.66
ASHBBPRJ01-HMRDRCRJ02-BE ASHBBPRJ01 ae2.0 ASHBBBRJ02 ae11.0 MRFDBBRJ02 ae0.0 MRFDBBRJ01 ae4.0 NRFKBBRJ01 ae6.0 VBCHBBRJ01 ae0.0 VBCHDSRJ01 ae18.0 HMRDRCRJ023125.79
ASHBBPRJ01-MCDLDSRJ01-BE ASHBBPRJ01 ae2.0 ASHBBBRJ02 ae9.0 MCDLBBRJ01 ae0.0 MCDLDSRJ01 3862.34
ASHBBPRJ01-MRFDDSRJ02-10-BE ASHBBPRJ01 ae2.0 ASHBBBRJ02 ae11.0 MRFDBBRJ02 ae1.0 MRFDDSRJ02 2110.26
ASHBBPRJ01-MRFDDSRJ02-11-BE ASHBBPRJ01 ae2.0 ASHBBBRJ02 ae11.0 MRFDBBRJ02 ae1.0 MRFDDSRJ02 2110.26
ASHBBPRJ01-MRFDDSRJ02-12-BE ASHBBPRJ01 ae2.0 ASHBBBRJ02 ae11.0 MRFDBBRJ02 ae1.0 MRFDDSRJ02 2110.26
ASHBBPRJ01-MRFDDSRJ02-13-BE ASHBBPRJ01 ae2.0 ASHBBBRJ02 ae11.0 MRFDBBRJ02 ae1.0 MRFDDSRJ02 2110.26
ASHBBPRJ01-MRFDDSRJ02-14-BE ASHBBPRJ01 ae2.0 ASHBBBRJ02 ae11.0 MRFDBBRJ02 ae1.0 MRFDDSRJ02 2110.26
部分比较_interfaces_high_med.txt
ASHBBBRJ02 ae5.0 9% 31% medium_increase
DALSBBRJ02 ae10.0 34% 0% medium_decrease
DALSBBRJ02 ae4.0 3% 44% medium_increase
DUKEBBRJ01 ae0.0 24% 75% high_increase
DUKEBBRJ01 ae5.0 56% 0% high_decrease
DUKEBBRJ02 ae2.0 5% 57% high_increase
DUKEBBRJ02 ae6.0 15% 73% high_increase
答案 0 :(得分:0)
我最后只使用sed删除百分号,然后在awk语句中重新添加它。