문제

Please let me know what is wrong with below code:

#!/bin/csh
set str = "peanut"
set sr = "an"
awk 'BEGIN { print index($str,$sr) }'

The error is awk: Field is not correct. The source line number is 1.

도움이 되었습니까?

해결책

The $variable strings are not interpreted by Csh within the 'single quotes'.

Perhaps the simplest fix is to use (GNU) Awk variables as command-line parameters:

#!/bin/csh
set str = "peanut"
set sr = "an"
awk -vstr=$str -vsr=$sr 'BEGIN { print index(str, sr)}'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top