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:
- Contains characters a - z, A - Z, digits 0 - 9, or underscore
- Starts with a capital letter A - Z
- 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