【发布时间】:2021-09-04 17:39:00
【问题描述】:
我有一个查询生成的结果文件。该文件有 2 列。第一个是名称,第二个是 id.. 现在我有一个 id 变量。我必须将此 id 变量与第二列中的值进行比较并打印输出如下。 文件
sam,12
justin,12,
jarvis,14
现在 $id = 12。输出应该如下
sam is having same id as main id $id
justin is having same id as main id $id
jarvis id does not matches with main id $id
我在下面尝试过,但没有产生所需的输出。谁能指导我哪里做错了
#!/bin/bash
awk 'BEGIN {FS=","}
{ if ($2 == $id)
echo "$1 is having same id as main id $id "
else
echo "$1 id does not matches with main id $id" ' > a.txt
【问题讨论】:
标签: linux shell unix scripting