Re: "sed" question

Liste des GroupesRevenir à cu shell 
Sujet : Re: "sed" question
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.unix.shell
Date : 08. Mar 2024, 01:09:41
Autres entêtes
Organisation : None to speak of
Message-ID : <87bk7poa7u.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Grant Taylor <gtaylor@tnetconsulting.net> writes:
On 3/6/24 19:54, Janis Papanagnou wrote:
You see that there's then (per default) only single delimiting
spaces left.
>
I think I see what you're saying.  I also feel like I must be missing
something obvious, because what you're describing is what I would
expect awk to do.
I know that's what awk does, but I don't think I would have expected it
if I didn't know about it.
For example:
$ echo 'one  two   three' | awk '{print}'
one  two   three
$ echo 'one  two   three' | awk '{$0 = $0 " four" ; print}'
one  two   three four
$ echoʜ'one  two   three' | awk '{$2 = "TWO" ; print}'
one TWO three
$
$0 is the current input line.  If you don't change anything, or if you
modify $0 itself, whitespace betweeen fields is preserved.  If you
modify any of the fields, $0 is recomputed and whitespace between tokens
is collapsed.
awk *could* have been defined to preserve inter-field whitespace even
when you modify individual fields, and I think I would have found that
more intuitive.  (And ideally there would be a way to refer to that
inter-field whitespace.)  The fact that modifying a field has the side
effect of messing up $0 seems counterintuitive.
Perhaps the behavior matches your intuition better than it matches mine.
(And perhaps this should be moved to comp.lang.awk if it doesn't die out
soon.  Though both sed and awk are both languages in their own right and
tools that can be used from the shell, so I'd argue there's a topicality
overlap.)
[...]
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
8 Mar 24 * Re: "sed" question4Grant Taylor
8 Mar 24 `* Re: "sed" question3Keith Thompson
8 Mar 24  +- Re: "sed" question1Keith Thompson
8 Mar 24  `- Re: "sed" question1Grant Taylor

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal