How to handle a file using key,value pair in shell

2019-08-29 09:10发布

I have a file with below format and I want handle using key, value pair.

Format:

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

Pseudo code:

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  

Can anyone how to get the key and values using shell script ?

标签: linux shell unix
1条回答
等我变得足够好
2楼-- · 2019-08-29 09:57

Something like that?

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"
查看更多
登录 后发表回答