[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Sysadmin Lists
Subject: Re: Printing TITLE, SUBTITLE, and KEYWORDS
Date: Mon, 6 Feb 2023 15:03:23 +0100 (CET)

> ------------------------------
> Message: 5
> Date: Sun, 5 Feb 2023 07:26:32 +0100 (CET)
> From: Hans Lonsdale <>
> To: Greg Wooledge <>,
> Subject: Re: Printing TITLE, SUBTITLE, and KEYWORDS
> Message-ID: <>
> Content-Type: text/plain; charset=utf-8
> > It does a HELL of a lot more than that.  Did someone else write that
> > regex for you?  Do you even understand it?
> I did write it and understand it.  It allows spaces before the comments and 
> spaces after.
> Comments would be composed of ## or !! or @c or // for possibility of 
> different languages.

You're carrying over a lot of code and logic from your first attempt in sed
that are unnecessary in awk.

$0 ~ /\[START\]  # matches lines that contain your start patterns, making
comment chars irrelevant.  It can even be simplified to just: /\[START\]/
Pattern tests are applied to $0 by default.

You can strip leading comment chars from lines you want to print by deleting
the first field or stripping it:
$1 = "" # sets the first field to the null string (deleting unwanted chars)
sub(/^[##|!!|@c|\/\//, "") # deletes unwanted chars without affecting NF

Changes made to $0 in earlier statement blocks propagate to lower pattern tests
as well:
/\[START\]/ { $1 = "" }
Changes $0 for all remaining pattern tests on this line (record).

Sent with  
Secure and private email

reply via email to

[Prev in Thread] Current Thread [Next in Thread]