LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-03-2023, 02:31 PM   #1
Faki
Member
 
Registered: Oct 2021
Posts: 574

Rep: Reputation: Disabled
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?
 
Old 04-04-2023, 12:45 AM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,809

Rep: Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209
Code:
if (uclass == "") uclass="[[:graph:]]+
if (uclass !~ /^[(].*[)]$/) uclass=("(" uclass ")")
If you know there is never a "( )" supplied then you can omit the second condition.
 
  


Reply

Tags
bash



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
User input into Bash scripts and checking validity of user input?? helptonewbie Programming 8 07-07-2008 06:40 PM
Repeated "input: AT Translated Set 2 keyboard as /class/input/input" messages AcerKev Mandriva 2 09-16-2007 08:35 AM
Squid User Grouping dan0r Linux - Software 1 03-06-2006 11:14 AM
Gnome Grouping Windows maelstrom209 Linux - Software 1 12-25-2004 06:58 PM
bash - while + until loops grouping? trees Linux - General 2 02-19-2004 02:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration