From owner-freebsd-questions@freebsd.org Thu Dec 7 01:26:35 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F1800E94976 for ; Thu, 7 Dec 2017 01:26:35 +0000 (UTC) (envelope-from johnl@iecc.com) Received: from gal.iecc.com (gal.iecc.com [IPv6:2001:470:1f07:1126:0:43:6f73:7461]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "gal.iecc.com", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 983516D623 for ; Thu, 7 Dec 2017 01:26:35 +0000 (UTC) (envelope-from johnl@iecc.com) Received: (qmail 72704 invoked from network); 7 Dec 2017 01:26:34 -0000 Received: from unknown (64.57.183.53) by gal.iecc.com with QMQP; 7 Dec 2017 01:26:34 -0000 Date: 7 Dec 2017 01:26:12 -0000 Message-ID: <20171207012612.41249.qmail@ary.lan> From: "John Levine" To: freebsd-questions@freebsd.org Cc: zarniwhoop@ntlworld.com Subject: Re: grep problem In-Reply-To: <20171207010801.GA10604@milliways.localdomain> Organization: X-Headerized: yes Mime-Version: 1.0 Content-type: text/plain; charset=utf-8 Content-transfer-encoding: 8bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Dec 2017 01:26:36 -0000 In article <20171207010801.GA10604@milliways.localdomain> you write: >> $ echo 'a-b' | grep '-b' >> Usage: grep [OPTION]... PATTERN [FILE]... >> Try `grep --help' for more information. >> >> $ echo 'a-b' | grep '\-b' >> a-b >In gnu grep, '-' indicates it should read from STDIN, I assume that >FreeBSD's grep is the same. Close, but not quite. A quick peek at the grep man page (you did look at the man page, didn't you?) reveals that -b is a flag telling what byte offset to start at. A more normal way to prevent your pattern from being treated as a flag is to tell it that it's a pattern: $ echo a-b | grep -e -b R's, John