Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- NAME_REGEX=".*"
- LINE_L=1
- LINE_R=-1
- DIR="."
- ER () {
- echo $1
- exit 1
- }
- while [[ $# > 0 ]]; do
- arg=$1
- shift
- case $arg in
- -name)
- NAME_REGEX=$1
- shift
- ;;
- -l)
- SEG=$1
- ## TODO parse the info
- if [[ $SEG =~ .*:.* ]]; then
- ## two parameters
- LINE_L=${SEG%:*}
- LINE_R=${SEG##*:}
- else
- LINE_L=$SEG
- LINE_R=$SEG
- fi
- if (($LINE_L == 0)); then
- ER "LINE cannot be 0 sorry QQ"
- fi
- shift
- ;;
- *)
- DIR=$arg
- ;;
- esac
- done
- for i in $(find $DIR -type f); do
- if ! [[ $(basename $i) =~ $NAME_REGEX ]]; then
- continue
- fi
- echo "Processing file $(basename $i):"
- ALL=$(wc -l < $i)
- L=$LINE_L
- R=$LINE_R
- if (( $L < 0 )); then
- L=$((ALL+L+1))
- if (( $L < 0 )); then
- L=1
- fi
- fi
- if (( $R < 0 )); then
- R=$((ALL+R+1))
- fi
- if (( $L > $R )); then
- continue
- fi
- sed -n "${L},${R}p" < $i
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement