我和新來砸腳本,並有製表delimted文本文件,下面的列如果-conditionw用「+」和「 - 」符號在bash
A234 + -
B654 - +
C630 + +
D707 - -
我想比較遍歷的每一行文件和比較第二和第三列獲得一個輸出像在一個文本文件
A234 Plus and Minus
B654 Minus and Plus
C630 Plus and Plus
D707 Minus and Minus
這裏下面是我的bash腳本
#!/bin/bash
filename="$1"
while read line;
do
g_symbol=$(echo $line | awk '{print $2}')
t_symbol=$(echo $line | awk '{print $3}')
if [[($g_symbol == "+") && ($t_symbol == "-")]]
then
echo $filename "PLus and Minus"
elif [[($g_symbol == "-") && ($t_symbol == "-")]]
then
echo $filename "Minus and Minus"
elif [[($g_symbol == "-") && ($t_symbol == "+")]]
then
echo $filename "Minus and Plus"
else
echo $filname "Plus and Plus"
fi
done < "$filename"
但是當我執行它時,出現以下錯誤
[[(+: command not found
[[(-: command not found
[[(-: command not found
[[(+: command not found
請引導我。
你有你的測試語法錯誤。在'[[($ g_symbol ==「+」)&&($ t_symbol ==「 - 」)]]'你忘了空格。你需要編寫'[[($ g_symbol ==「+」)&&($ t_symbol ==「 - 」)]]''。您需要在所有其他測試中添加這些空格。另外,我不認爲'[[]]'測試處理嵌套測試。 – Aserre
這可能會更快,而不是'awk',而是'read id g_symbol t_symbol'。 – choroba
@choroba如何在不使用awk的情況下將2列和3列的值存儲到各個變量中。請引導我。我是bash的新手 – Chudar