根据请求,投递代码分开。
电流输出
Name,Final Grade,Section
Andrew is an online student
Andrew,95,online
Brandon is an online student
Brandon,100,online
Chelsey is an onsite student
Chelsey,100,onsite
Deborah is an online student
Deborah,72,online
Erik is an online student
Erik,65,online
Arielle is an onsite student
Arielle,88,onsite
Shaun is an onsite student
Shaun,91,onsite
Ninette is an online student
Ninette,82,online
Nguyen is an onsite student
Nguyen,80,onsite我应该实现的输出
Andrew is an online student
Brandon is an online student
Chelsey is an onsite student
Deborah is an online student
Erik is an online student
Arielle is an onsite student
Shaun is an onsite student
Ninette is an online student
Nguyen is an onsite student基本上,它是从输入文件中添加行,而不是删除标头。我的问题是移除它
#!/usr/bin/awk -f
##comment create awk script that will output the given data in the format given in word document
##comment specify the delimiter as ","
BEGIN { FS = "," }
/./ {
##comment check if the third field is online, if print online
if ($3 == "online")
printf("%s is an online student\n", $1)
##commentcheck if the third field is onsite, if print onsite
if ($3 == "onsite")
printf("%s is an onsite student\n", $1)
} $1发布于 2021-11-02 21:17:16
在shell脚本中,$1引用了调用脚本的第一个位置参数(或参数)--您可能习惯于使用该参数将文件名传递给一次性丢弃awk计划。
然而,在可执行的awk程序内部,命令行参数是通过awk自己的ARGV数组在内部处理的,$1是当前记录的第一个字段。在代码块之外,它等价于
$1 != "" {
print
}因此,它输出至少包含一个非FS字符的每一行输入。
所以去掉多余的$1。
https://unix.stackexchange.com/questions/675907
复制相似问题