标签:
#This script is to parse data file:
fun0()
{
#
#
[INFO1]
a=1 b=2 c=3
[INFO2]
a=7 b=8 c=9
[INFO3]
a=x b=y c=z
}
#! /bin/bash
read Info Abc
#echo $Info
if [ "$Info" != "INFO1" -a "$Info" != "INFO2" -a "$Info" != "INFO3" ]
then
echo "Wrong INFO!"
exit 0
fi
sed ‘/^#\|^$/d‘ $1 | grep -A1 "$Info" | tail -1 | awk -F‘[= ]+‘ -v var="$Abc" ‘{if(var==$1){print $2}
else if(var==$3){print $4}
else if(var==$5){print $6}
else {print "Wrong abc!"}}‘
#some NOTES
#awk ‘BEGIN {FS="[= ]+"} {print $2}‘
#awk –v nvar="$var" ‘BEGIN{print nvar}‘
fun1()
{
read num1 num2
echo Add is $(($num1+$num2+1))
}
Using of grep sed awk on Linux
标签:
原文地址:http://www.cnblogs.com/xiaochou/p/grep_sed_awk.html