Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- voor=0
- na=0
- while getopts ":a:b:" opt
- do
- case $opt in
- a) #n regels die volgen op passage uitschrijven
- na=$OPTARG;;
- b) #n regels voorafgaand aan passage uitschrijven
- voor=$OPTARG;;
- \?)
- echo "Syntax: highlight [-a <int>] [-b <int>] <int>:<int> <int>:<int>" 1>&2
- exit 1
- esac
- done
- shift $(($OPTIND - 1))
- if [[ $# != 2 || ! $( echo $1 | grep "[0-9]*:[0-9]*" ) || ! ! $( echo $2 | grep "[0-9]*:[0-9]*" ) ]]
- then
- echo "Syntax: highlight [-a <int>] [-b <int>] <int>:<int> <int>:<int>" 1>&2
- exit 1
- else
- touch bestand
- regel=$( echo $1 | sed -e "s/^\([0-9]*\):[0-9]*$/\1/" )
- char=$( echo $1 | sed -e "s/^[0-9]*:\([0-9]*\)$/\1/" )
- regeltwo=$( echo $2 | sed -e "s/^\([0-9]*\):[0-9]*$/\1/" )
- chartwo=$( echo $2 | sed -e "s/^[0-9]*:\([0-9]*\)$/\1/" )
- if [[ $regel = $regeltwo && $char -gt $chartwo ]]
- then
- echo "highlight: bad interval" 1>&2
- exit 2
- elif [[ $regel -gt $regeltwo ]]
- then
- echo "highlight: bad interval" 1>&2
- exit 2
- elif [[ $char -le 0 || $chartwo -le 0 || $regel -le 0 || $regeltwo -le 0 ]]
- then
- echo "highlight: bad interval" 1>&2
- exit 2
- else
- IFS=' '
- head -n $regeltwo <&0 | tail -n $(($regeltwo - $regel + 1)) >>bestand
- sed -i -e "$ s/./&\\\033[0m/$chartwo" bestand
- sed -i -e "1s/./\\\033[1m&/$char" bestand
- echo -e $(cat bestand)
- rm bestand
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement