在shell中取文件的某一行的某一列的方法之一

需求:根据配置文件检测板子是否配置成功……

#!/bin/bash

standFile="$1"
num=`cat $standFile | wc -l`
for((i=1;i<=$num;i++))
do
  for rl in $i
  do
    # 读取standFile文件的第i行第1列的值,并赋给tmp1
    tmp1=$(awk -v hang="${i}" 'NR==hang {print $1}' ${standFile})
    # 读取standFile文件的第i行第3列的值,并赋给tmp2
    tmp2=$(awk -v hang="${i}" 'NR==hang {print $3}' ${standFile})
    res="`xmlconfig r $tmp1`"
    fin_res=${res##*=}
    # 对比
    if [ $fin_res == $tmp2 ]
    then
      echo "$tmp1 is success"
    else
      echo "$tmp1 is failed"
    fi
  done
done

 

你可能感兴趣的:(Linux)