码迷,mamicode.com
首页 > 系统相关 > 详细

Using of grep sed awk on Linux

时间:2016-04-04 22:49:35      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:

#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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!