Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

awk code to inspect variable before printing

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 1 Week Ago   -   Original Discussion by SkySmart
SkySmart's Unix or Linux Image
SkySmart SkySmart is offline
Registered User
Join Date: Dec 2006
Last Activity: 27 May 2018, 11:18 PM EDT
Posts: 917
Thanks: 754
Thanked 3 Times in 3 Posts
Originally Posted by RudiC View Post
As the sample doesn't contain the "WrongValue" string, you don't seem to want that condition tested.

Would this come close to what you need?

printf '%s\n' "${RawContent}" |
awk '
/##  Beginning Stages  ##/,
/## Ending Stages ##/   {if (!/^#.*\!|DefaultError/)    {TMP = TMP DL $0
                                                         DL = ORS
                         if (/## Ending Stages ##/)     {if (TMP !~ /WrongValue/) print TMP
                                                         DL = TMP = ""

How is the "RawContent" variable populated? If by reading a file, it might be more efficient to work on that file immediately circumventing the variable assignment.
Thank you for your patience with me.

1. The "RawContent" variable is populated as an output from another program. It is not a file.
2. My mistake. I forgot to include the WrongValue in the content. But, the thing is, sometimes the RawContent variable will contain it. Other times, it wont.

Thanks again!
Sponsored Links
Old Unix and Linux 1 Week Ago   -   Original Discussion by SkySmart
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Join Date: Jul 2012
Last Activity: 28 May 2018, 3:43 AM EDT
Location: Aachen, Germany
Posts: 12,756
Thanks: 417
Thanked 3,923 Times in 3,607 Posts
Why not pipe that other program's output into the awk script immediately? If, on top, you need it for other, different purposes, use the tee command to create an temp file.
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Issue when printing filename through cygwin using a variable with awk alvinoo Shell Programming and Scripting 1 06-17-2015 10:44 PM
[awk] printing value of a variable assignment from a file sea Shell Programming and Scripting 2 05-15-2015 02:00 AM
problem with printing out variable in awk ymc1g11 Homework & Coursework Questions 5 04-16-2012 04:32 PM
Printing a variable column using awk The Gamemaster Shell Programming and Scripting 2 12-20-2011 09:03 AM
Awk Issues - Not printing the 10th Variable. Junes Shell Programming and Scripting 1 09-22-2011 06:03 AM

All times are GMT -4. The time now is 04:22 AM.