awk help

Polytropon freebsd at edvax.de
Sun Sep 10 18:18:50 UTC 2017


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, ...


More information about the freebsd-questions mailing list