LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-26-2023, 01:33 PM   #1
Faki
Member
 
Registered: Oct 2021
Posts: 574

Rep: Reputation: Disabled
Detecting a user set pattern in awk


I want to match certain lines composed of three patterns with the possibility for the user to supply them. If the patterns are not supplied by the user, they are defaulted. However the last pattern is optional.

Have written the following awk script

Code:
BEGIN {
  display = 0
  if (ukingd == "") ukingd="([[:graph:]]+)"
  if (uclass == "") uclass="([[:graph:]]+)"
  if (ufamil == "") ufamil="([[:print:]]*)" 
}

match($0, beg_ere, maggr) {
  if ( ! ufamil ) { display = 1 }  # <== problem
  else { do_something }
} 

display { sub(km_ere, " ") ; print }
But I have a problew (shown above). I want to set display = 1 when the user does not supply a pattern for ufamil. But because I default its value, the default makes the script think that it was user supplied.
 
Old 03-27-2023, 02:24 PM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Perhaps you want
Code:
if (ufamil == "") { ufamil="([[:print:]]*)"; display = 1 }
 
  


Reply

Tags
awk



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
[SOLVED] sed inside awk or awk inside awk maddyfreaks Linux - Newbie 4 06-29-2016 01:10 PM
[SOLVED] Once again... awk.. awk... awk shivaa Linux - Newbie 13 12-31-2012 04:56 AM
substitute a pattern only if some other pattern is present raghu123 Programming 3 06-26-2009 06:53 AM
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
replace a text pattern with the reverse of another text pattern lothario Linux - Software 5 07-25-2008 02:43 PM

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

All times are GMT -5. The time now is 05:29 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