I'm updating a bash script (for Mac) that I have not looked at in a while and I want to copy the characters of a filename up to \_\_ (two underscores). What I have currently grabs the first 6 characters, and pastes it fine, but I'm not sure how to change it to copy everything up to the first two underscores (not \_ or a single underscore).

```
#This copies the first 6 characters of the FILENAME 
#and adds it to the top of the same file
#!/bin/bash
for filename in ./*.txt
do
    text="${filename:2:6}"
    echo $text | cat - $filename > temp && mv temp $filename;
done;

```

Thanks in advance for the help :)