Using of grep sed awk on Linux
Posted bob
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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))
}
以上是关于Using of grep sed awk on Linux的主要内容,如果未能解决你的问题,请参考以下文章
Linux bash 文本处理命令awk,sed,grep 用法