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

1
  • 2
    In addition to the answer by @choroba, change the while line like this: while IFS="" read -r line; do. Commented Jul 21, 2016 at 8:46

1 Answer 1

3

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

regex=$'^\t+'

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.