Last active
August 29, 2015 13:57
-
-
Save nvarun/9575155 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ksh | |
##DESC====================================================================== | |
### Extracts block of code/section based on two arguments; | |
### 1 - Source Code File, or Git Diff Output | |
### 2 - Extract Pattern | |
##====================================================================== | |
function fn__extrt_block { | |
test $# -ne 2 && exit 1 | |
test -f $1 && fv_iputFile=$1 || exit 2 | |
fv_srchPtrn="$2" | |
fv_funcWorkDir=$HOME/${0} | |
mkdir -p ${fv_funcWorkDir} && cd ${fv_funcWorkDir} | |
grep -n "${fv_srchPtrn}" ${fv_iputFile} | cut -d':' -f1 > outfile | |
while true | |
do | |
echo $(head -2 outfile) | read LB UB | |
test ! -z ${UB} && UB=`echo ${UB} - 1 | bc` | |
echo "${LB},${UB:-\$}p" > sed_scpt | |
sed -n -f sed_scpt ${fv_iputFile} > file__${LB}_${UB:-$} | |
sed '1d' outfile > outfile.n | |
mv outfile.n outfile | |
test ! -s outfile && break | |
done | |
rm -f outfile* sed_scpt | |
echo "INFO: Listing Generated Files" | |
ls -ltr file__* | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment