- 论坛徽章:
- 10
|
- #!/bin/bash
- #sed -n '/a1/,/a2/p'|sed '$d'
- read -p "Please enter (eg:a1):" choice
- [ -z $choice ] && exit 1
- a=`echo $choice|cut -c 1`
- b=`echo $choice|cut -c 2-`
- expr $b + 1 >/dev/null 2>&1
- [ $? -ne 0 ] && echo "Input error" && exit 2
- c=$(($b+1))
- cat file|sed -n '/a'$b'/,/a'$c'/p'|sed '$d'
复制代码 缩写版如下- #!/bin/bash
- file=file
- read -p "Please enter (eg:a1):" choice
- [ -z $choice ] && exit 1
- expr ${choice:1} + 1 &>/dev/null
- [ $? -ne 0 ] && exit 2
- sed -n '/a'${choice:1}'/,/a'$((${choice:1}+1))'/p' $file | sed '$d'
复制代码 用法直接改一下文件名然后回车 |
|