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

2019-08-29 09:41发布

问题:

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 ?

回答1:

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"


标签: linux shell unix