如何使用 unix shell 脚本 awk 从文本文件中提取一些行。
例如 1) 输入:file_name_test.txt
**<header> asdfdsafdsf**
11 asd sad
12 sadf asdf
13 asdfsa asdf
14 asd sdaf
**15 asd asdfsdf
16 sadfsadfsaf sdfsdf
17 asdf sdaf
18 asfd saf
19 sadf asdf
10 asf asf**
2)预期输出:
**<header> asdfdsafdsf
15 asd asdfsdf
16 sadfsadfsaf sdfsdf
17 asdf sdaf
18 asfd saf
19 sadf asdf
10 asf asf**
3) test.sh 的代码:
FILENAME=$1
threshold=$2
awk '{line_count++;
if (line_count==1 || (line_count>$threshold))
print $0;
}' $FILENAME > overflow_new2
4)
sh test.sh file_name_test.txt 5
5)它只打印第一行:
<header> asdfdsafdsf
在输出文件overflow_new2 中。并在腻子中返回这些行:
awk: Field $() is not correct.
The input line number is 2. The file is file_name_test.txt
The source line number is 2.
任何的想法?谢谢你。