Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Sep 2017 20:18:38 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Ernie Luzar <luzar722@gmail.com>
Cc:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Re: awk help
Message-ID:  <20170910201838.88b15b21.freebsd@edvax.de>
In-Reply-To: <59B53ED2.3000409@gmail.com>
References:  <59B53ED2.3000409@gmail.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Sun, 10 Sep 2017 09:32:02 -0400, Ernie Luzar wrote:
> Hello list;
> 
> I wrote the following script to read a hosts file I downloaded
> containing known bad sex domain names intended for addition to
> /etc/hosts file. This script drops some useless records and builds
> a local-zone: record for input to unbound. The file contains 55,000
> records and this script takes 7 minutes to process it.
> 
> I know awk can do this same thing must faster. I have searched awk
> and can not find any reference that would do what the tr '\r' ' '`
> command does.

I'd simply drop the ^Ms in a first step, then continue processing
with awk, writing the output to the desired file:

	#!/bin/sh
	cat input.txt | tr -d '\r' | awk '
		# ...
		# your awk code here
		# ...
	' > output.txt

You can use variables or command line parameters for input.txt and
output.txt to increase modularity.

NB: Useless use of "cat". ;-)



> Would some one point me to documentation with example of how to get
> the same result with awk as the tr '\r' ' '` command does.

Why do you want to replace the \r with a space? Just delete it,
nobody (except people in "Windows" land) actually need it! :-)



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20170910201838.88b15b21.freebsd>