From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from minnie.tuhs.org (minnie.tuhs.org [45.79.103.53]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id ac605856 for ; Sun, 13 Oct 2019 14:35:38 +0000 (UTC) Received: by minnie.tuhs.org (Postfix, from userid 112) id C71069B9CB; Mon, 14 Oct 2019 00:35:36 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 1AF50946B9; Mon, 14 Oct 2019 00:35:07 +1000 (AEST) Received: by minnie.tuhs.org (Postfix, from userid 112) id 5394B946B9; Mon, 14 Oct 2019 00:35:04 +1000 (AEST) X-Greylist: delayed 2508 seconds by postgrey-1.36 at minnie.tuhs.org; Mon, 14 Oct 2019 00:35:03 AEST Received: from seine.is.ed.ac.uk (seine.is.ed.ac.uk [129.215.17.202]) by minnie.tuhs.org (Postfix) with ESMTPS id 0BE1A93DBB for ; Mon, 14 Oct 2019 00:35:02 +1000 (AEST) Received: from crunchie.inf.ed.ac.uk (crunchie.inf.ed.ac.uk [129.215.202.41]) by seine.is.ed.ac.uk (8.14.7/8.14.7) with ESMTP id x9DDrDem009105 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 13 Oct 2019 14:53:13 +0100 Received: from macaroni.inf.ed.ac.uk (macaroni.inf.ed.ac.uk [129.215.197.42]) by crunchie.inf.ed.ac.uk (8.14.7/8.14.7) with ESMTP id x9DDrBuP032674 for ; Sun, 13 Oct 2019 14:53:12 +0100 Received: by macaroni.inf.ed.ac.uk (Postfix, from userid 26013) id E0F4C292AD4E; Sun, 13 Oct 2019 14:53:44 +0100 (BST) From: Richard Tobin To: tuhs@tuhs.org In-Reply-To: Larry McVoy's message of Thu, 10 Oct 2019 19:56:54 -0700 X-Mailer: Ream 5.1.51-richard-mac Message-Id: <20191013135344.E0F4C292AD4E@macaroni.inf.ed.ac.uk> Date: Sun, 13 Oct 2019 14:53:44 +0100 (BST) X-Edinburgh-Scanned: at seine.is.ed.ac.uk with MIMEDefang 2.84, Sophie, Sophos Anti-Virus, Clam AntiVirus Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 129.215.17.202 Subject: [TUHS] Awk for CSV files X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" I was reminded of this by Larry's comment: > I miss Brian on this list. I've interacted with him over the years, the > one I remember the most was I was trying to do an awk like interface to a > key/value "database". Recently I've had to deal with a lot of data in CSV (comma-separated-value) format. Awk is *almost* prefect for this, but of course doesn't handle the quoting of fields that contain commas. One can usually work around it by finding a character that doesn't occur in the data and converting the CSV file to use that as the separator, but it's not ideal. Awk's input could easily be modified to handle CSV files, but output would be a bit more difficult, because you don't specify field boundaries explicitly on output. One possibility would be a printf() format specifier that takes a field and quotes it appropriately. -- Richard -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.