From nobody Tue Feb 21 11:53:14 2023 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PLd33031fz3sGgr for ; Tue, 21 Feb 2023 11:53:19 +0000 (UTC) (envelope-from sysadmin.lists@mailfence.com) Received: from mailout-l3b-97.contactoffice.com (mailout-l3b-97.contactoffice.com [212.3.242.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4PLd324vYpz46PR for ; Tue, 21 Feb 2023 11:53:18 +0000 (UTC) (envelope-from sysadmin.lists@mailfence.com) Authentication-Results: mx1.freebsd.org; none Received: from ichabod.co-bxl (ichabod.co-bxl [10.2.0.36]) by mailout-l3b-97.contactoffice.com (Postfix) with ESMTP id 2818A9A5; Tue, 21 Feb 2023 12:53:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1676980397; s=20210208-e7xh; d=mailfence.com; i=sysadmin.lists@mailfence.com; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding; l=2996; bh=Q+EjNKtMvqCGjMk6wpJp/xUo68vHCZ8i0ivskGl0lBA=; b=jq5m5LLF1KyeVktyTLfjIvWgV5f0MJoicZWi8TbUJSYqcBLm/LXjbJdS1Z8VDcyY 5Wjsew8MIaTwcbGtsYpWCLgNeSlyxsL6p35BL1mBXnNGVlY0JjRTfv64Ox+kgn6V/D7 jT/R50HaqnbzoOs5dLcPDYva/kqC1JlacgiknGxhSkMkHDu3uDCYlxRGmceK6oLWFcU ScUwl0O2q6ISIdJ5efwhT+DhlSA0ImcoNtN6lyN/2Nb8yp9HqLd4+wSyWDDs/i71FJi coO6JrljhPjVj8kZvTWb7P+7VF/jRduGZafxnpw3xbFnXWvf3tqUdGnMeDCvJyXsDYq 1UrCdAAbFw== Date: Tue, 21 Feb 2023 12:53:14 +0100 (CET) From: Sysadmin Lists To: Freebsd Questions Cc: =?utf-8?Q?Andreas_Kusalananda_K=C3=A4h=C3=A4ri?= Message-ID: <1653727721.225143.1676980394881@ichabod.co-bxl> In-Reply-To: References: <1600449078.170379.1676939080787@fidget.co-bxl> Subject: Re: BSD-awk print() Behavior List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Mailer: ContactOffice Mail X-ContactOffice-Account: com:312482426 X-Rspamd-Queue-Id: 4PLd324vYpz46PR X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:10753, ipnet:212.3.242.64/26, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N > ---------------------------------------- > From: Andreas Kusalananda K=C3=A4h=C3=A4ri > Date: Feb 21, 2023, 2:14:21 AM > To: Sysadmin Lists > Cc: Freebsd Questions > Subject: Re: BSD-awk print() Behavior >=20 >=20 > On Tue, Feb 21, 2023 at 01:24:41AM +0100, Sysadmin Lists wrote: > > > > $ cat file_{1,2} > > https://github.com/ > > https://github.com/ > > https://github.com/ > > https://github.com/ > >=20 > > $ diff file_{1,2} =20 > > 1,2c1,2 > > < https://github.com/ > > < https://github.com/ > > --- > > > https://github.com/ > > > https://github.com/ > >=20 > > $ awk '{ print $0 " abc " }' file_{1,2} =20 > > abc ://github.com/ > > abc ://github.com/ > > https://github.com/ abc=20 > > https://github.com/ abc=20 >=20 > file_1 is a DOS text file, while file_2 is a Unix text file. The DOS > text file, when interpreted by tools expecting Unix text, has an extra > carriage-return character at the end of each line. This carriage-return > character will be part of $0 in the awk code and causes the cursor to be > moved back to the start of the line when printing it, giving the effect > that you are seeing. >=20 > This has nothing to do with awk's print keyword. You would get similar > strange result if you simply pasted the data side by side: >=20 > =09$ paste file_{1,2} > =09https://https://github.com/ > =09https://https://github.com/ >=20 > Here, "https://github.com/" is first printed from the DOS text file, > after which the cursor is returned to the start of the line. Then, > paste inserts a tab character which "steps over" the eight first > characters that had already been outputted ("https://") and then outputs > "https://github.com/" from the Unix text file. >=20 >=20 > >=20 > > The sql-extracted URLs cause awk's print() to replace the front of the = string > > with text following $0. file_2 does not. I used vim's `:set list' optio= n to > > view hidden chars, but there's no apparent difference between the two -= - > > although `diff' clearly thinks so. Both files show this when `list' is = set: > >=20 > > https://github.com/$ > > https://github.com/$ >=20 > Yes, because Vim automatically interprets DOS text files as ordinary > text. I'm asssuming that while editing file_1 in Vim, you see "[dos]" > at the bottom of the screen? >=20 >=20 Good explanation. I found the hidden character before reading your email us= ing `cat -e' which printed the ^M character, but didn't know awk could move the cursor around like that. Sounds like a useful (and dangerous) hack. $ cat -e file_{1,2}=20 https://github.com/^M$ https://github.com/^M$ https://github.com/$ https://github.com/$ vim does indeed say [dos] at the bottom of file_1. Now I know sqlite3 creat= es dos files even on unix-like systems. Thank you both. --=20 Sent with https://mailfence.com =20 Secure and private email