如何使用shell脚本中的键值对处理文件

时间:2014-12-18 09:13:55

标签: linux shell unix

我有一个格式低于格式的文件,我希望使用键值对进行处理。

格式

table name=type of load    
Sample Data:
student=full
department=delta       

伪码

for(i=0;i<arr.size;i++)      
{                   
  if key.table_name=arr[i]               
  then  
    if value. Type_of_load=full      
     then      
         process some action
    else    
    if value.type_of_load=delta     
      then     
          process some action   
    fi  
  fi  
fi  

任何人都可以使用shell脚本获取密钥和值吗?

1 个答案:

答案 0 :(得分:0)

那样的东西?

while IFS== read -r key value; do
    case $key in
        delta)
            echo "key type of $value is delta"
            ;;
        full)
            echo "key type on $value is full"
            ;;
     esac
done < "$file"