Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #278: The Dilithium Crystals need to be rotated.


comp / comp.unix.shell / Re: "sed" question

SubjectAuthor
o Re: "sed" questionChristian Weisgerber

1
Subject: Re: "sed" question
From: Christian Weisgerber
Newsgroups: comp.unix.shell, comp.lang.awk
Followup: comp.lang.awk
Date: Sat, 9 Mar 2024 12:27 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: naddy@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell,comp.lang.awk
Subject: Re: "sed" question
Followup-To: comp.lang.awk
Date: Sat, 9 Mar 2024 12:27:05 -0000 (UTC)
Message-ID: <slrnuuolcp.2g4k.naddy@lorvorc.mips.inka.de>
References: <us9vka$fepq$1@dont-email.me> <usa01v$fj5h$1@dont-email.me>
<usagql$j9bc$1@dont-email.me>
Injection-Date: Sat, 9 Mar 2024 12:27:05 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="82069"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
View all headers

On 2024-03-06, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

>> $ awk '{print $1, "1-1"}' newsrc-news.eternal-september.org-test >
>> newsrc-news.eternal-september.org
>
> In this specific case of regular data you can simplify that to
>
> awk '$2="1-1"' sourcefile > targetfile

That had me scratching my head. You can't have an action without
enclosing braces. But it's still legal syntax because... it's an
expression serving as a pattern. The assignment itself is a side
effect.

Care needs to be taken when using this shortcut so the expression
doesn't evalute as false:

$ printf 'one 1\ntwo 2\nthree 3\n' | awk '$2=4'
one 4
two 4
three 4
$ printf 'one 1\ntwo 2\nthree 3\n' | awk '$2=0'
$

$ printf 'one 1\ntwo 2\nthree 3\n' | awk '$2="4"'
one 4
two 4
three 4
$ printf 'one 1\ntwo 2\nthree 3\n' | awk '$2=""'
$

--
Christian "naddy" Weisgerber naddy@mips.inka.de

1

rocksolid light 0.9.8
clearnet tor