Home Man
Search
Today's Posts
Register

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

Tags
shell scripts

👤 Login to reply

 
Thread Tools Search this Thread
# 8  
Old 05-19-2018
Quote:
Originally Posted by RudiC
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?
Code:
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!
# 9  
Old 05-19-2018
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.
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[awk] printing value of a variable assignment from a file sea Shell Programming and Scripting 2 05-15-2015 02:00 AM
Variable substitution in array printing say170 Shell Programming and Scripting 2 09-03-2014 11:20 AM
printing variable with variable suffix through loop oly_r Shell Programming and Scripting 4 06-26-2012 02:00 PM
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
Redirecting stdout to variable while printing it ocirne94 Shell Programming and Scripting 2 03-18-2011 04:46 PM
Replace variable with its value while printing dashing201 Shell Programming and Scripting 2 04-29-2010 03:11 AM
how to inspect the bytes in a file? sneakyimp Programming 7 04-14-2009 04:02 PM
sed not printing variable orahi001 UNIX for Dummies Questions & Answers 2 03-16-2008 08:21 PM


All times are GMT -4. The time now is 03:15 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password