你的位置:首页 > 操作系统

[操作系统]Using of grep sed awk on Linux


#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))
}