[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Printing TITLE, SUBTITLE, and KEYWORDS
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 <hanslonsdale@mailfence.com>
> To: Greg Wooledge <greg@wooledge.org>, help-bash@gnu.org
> Subject: Re: Printing TITLE, SUBTITLE, and KEYWORDS
> Message-ID: <326679125.319592.1675578392357@ichabod.co-bxl>
> 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 https://mailfence.com
Secure and private email
- Printing TITLE, SUBTITLE, and KEYWORDS, Hans Lonsdale, 2023/02/03
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Dennis Williamson, 2023/02/03
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Greg Wooledge, 2023/02/03
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Hans Lonsdale, 2023/02/04
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Greg Wooledge, 2023/02/04
- Re: Printing TITLE, SUBTITLE, and KEYWORDS, Hans Lonsdale, 2023/02/05
- Re: Printing TITLE, SUBTITLE, and KEYWORDS,
Sysadmin Lists <=