这是示例文件:
someText here some other columns (exist but I don't intend to read them)
anotherText there some other columns (exist but I don't intend to read them)
YouAreGood here some other columns (exist but I don't intend to read them)
HeIsNormal there some other columns (exist but I don't intend to read them)
Run Code Online (Sandbox Code Playgroud)
我想检查第二列是否为here,然后执行某些操作。
这是我的尝试,我不确定如何正确:
#!/usr/bin/bash
awk '{print $2}' sample | while read -r line
do
if [ "$line" == 'here' ]
then
echo "$line"
fi
done
Run Code Online (Sandbox Code Playgroud)
第二个文件中的预期输出:
someText
YouAreGood
Run Code Online (Sandbox Code Playgroud)
我想过使用awk '{print $2}' sample, or if [ "$line '{print $2}'" == 'here' ],但它else总是会执行块。
看起来这awk应该适合你:
awk '$2 == "here" {print $1}' file
someText
YouAreGood
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |