$ cat file
11 asasaw121
12 saasks122
13 sasjaks22
$ cat no
while read line
do
var=$(awk '{print $1}' $line)
echo $var
done<file
$ cat yes
while read line
do
var=$(echo $line | awk '{print $1}')
echo $var
done<file
$ sh no
awk: can't open file 11
source line number 1
awk: can't open file 12
source line number 1
awk: can't open file 13
source line number 1
$ sh yes
11
12
13
为什么第一个工作不起作用? awk希望在$ 1中找到什么?我认为理解这将帮助我避免许多脚本问题。awk在读取行为中的行为
我需要输入'#define SERVER @“http://10.35.42.54/ms0.8”'到特定的行。我如何使用'awk'或'sed'来实现这个功能? –
抱歉实现了什么?你想从'#define SERVER @“http:// 10.35.42.54/ms0.8'行中提取什么? – anubhava
只需要将这个字符串放在一个特定文本文件的第50行就可以了。就是这样。 –