1

I've tried to find all line's which begin with at least 1 tab. Several Variations didn't work out. The most Basic one:

#!/bin/bash

FILE=emptiness
{ while IFS=""; read line
do
regex='^[\t]+'
if [[ $line =~ $regex ]]; then
        echo "line with pattern found"
else
        echo "pattern not found"
fi

done

}< $FILE

Does anybody know whether it is even possible to find Tabs with the built in comparison function or how do it?

My Version is 4.1.2

  • 2
    In addition to the answer by @choroba, change the while line like this: while IFS="" read -r line; do. – Satō Katsura Jul 21 '16 at 8:46
3

You need to include the tab literally into the regex. You can use the $'' quotes for that:

regex=$'^\t+'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.