如何在shell脚本中使用键值对处理文件 [英] How to handle a file using key,value pair in shell script

查看:150
本文介绍了如何在shell脚本中使用键值对处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以下格式的文件,我想使用键值对进行处理.

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

格式:

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 脚本获取键和值吗?

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

推荐答案

类似的事情?

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"

这篇关于如何在shell脚本中使用键值对处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆