LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Introducing grouping characters in user input (https://www.linuxquestions.org/questions/linux-newbie-8/introducing-grouping-characters-in-user-input-4175723720/)

Faki 04-03-2023 02:31 PM

Introducing grouping characters in user input
 
I have an awk script that takes user input uclass. But can be defaulted if not supplied.

Code:

if (uclass == "") uclass="([[:graph:]]+)"
Customarily user input does not include the grouping clause () that allows me to capture the sub-pattern later.

How can I set the grouping characters around the user input if supplied?

MadeInGermany 04-04-2023 12:45 AM

Code:

if (uclass == "") uclass="[[:graph:]]+
if (uclass !~ /^[(].*[)]$/) uclass=("(" uclass ")")

If you know there is never a "( )" supplied then you can omit the second condition.


All times are GMT -5. The time now is 09:15 AM.