# Bash Coding

**URL:** <https://root-forum.cern.ch/t/bash-coding/50867>\
**Category:** Newbie\
**Created:** [July 20, 2022, 1:54am UTC](https://root-forum.cern.ch/t/bash-coding/50867 "2022-07-20T01:54:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_White](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/chris_white/32/30333_2.png) [@Chris\_White](https://root-forum.cern.ch/u/Chris_White)\
**Post date:** [July 20, 2022, 1:54am UTC](https://root-forum.cern.ch/t/bash-coding/50867/1 "2022-07-20T01:54:21Z")

</div>

I am new to the forum. I am a little lost trying to code this bash script to do the following:

find all words in a string that satisfy the following conditions:

1. Contains characters a - z, A - Z, digits 0 - 9, or underscore
2. Starts with a capital letter A - Z
3. Has at least one digit 0 - 9

Any character that does not fit the first condition can be used to separate distinct words.

Use regular expression(s) to search.

The string will be input manually

This is what I have:

while read LINE; do  
for word in $LINE; do  
if word =~ ^[0-9a-z\_A-Z]+ && $word =~ ^[A-Z] && $word =~ [0-9] ;then  
echo “$word”;  
fi  
done  
done

This is the output and error:

Test Input:

Theory Lab\_99 society Imagi4nation

Expected Output:

Lab\_99 Imagi4nation

Your Output:

(None)

stderr

/tmp/source.sh: line 3: Theory: command not found  
/tmp/source.sh: line 3: Lab\_99: command not found  
/tmp/source.sh: line 3: society: command not found  
/tmp/source.sh: line 3: Imagi4nation: command not found

Anyone have suggestions. This is bash v5.1

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 20, 2022, 5:16am UTC](https://root-forum.cern.ch/t/bash-coding/50867/2 "2022-07-20T05:16:24Z")

</div>

You will have better luck checking on a bash scripting forum (or just using google or any search engine), not on a ROOT forum like this 🙂 Anyway, maybe google for “grep regex”.
