From owner-freebsd-questions@FreeBSD.ORG Sun Dec 23 09:57:27 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C293CFB0 for ; Sun, 23 Dec 2012 09:57:27 +0000 (UTC) (envelope-from matthew@FreeBSD.org) Received: from smtp.infracaninophile.co.uk (smtp6.infracaninophile.co.uk [IPv6:2001:8b0:151:1:3cd3:cd67:fafa:3d78]) by mx1.freebsd.org (Postfix) with ESMTP id 49C408FC15 for ; Sun, 23 Dec 2012 09:57:27 +0000 (UTC) Received: from seedling.black-earth.co.uk (seedling.black-earth.co.uk [81.2.117.99]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.5/8.14.5) with ESMTP id qBN9vD9s041295 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Sun, 23 Dec 2012 09:57:13 GMT (envelope-from matthew@FreeBSD.org) DKIM-Filter: OpenDKIM Filter v2.7.3 smtp.infracaninophile.co.uk qBN9vD9s041295 Authentication-Results: smtp.infracaninophile.co.uk/qBN9vD9s041295; dkim=none reason="no signature"; dkim-adsp=none (insecure policy) Message-ID: <50D6D56E.8000401@FreeBSD.org> Date: Sun, 23 Dec 2012 09:57:02 +0000 From: Matthew Seaman User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Subject: Re: shell script problem References: <1356253535.76738.YahooMailClassic@web160101.mail.bf1.yahoo.com> <20121223103434.def7cd9c.freebsd@edvax.de> <20121223104311.557f3752.freebsd@edvax.de> In-Reply-To: <20121223104311.557f3752.freebsd@edvax.de> X-Enigmail-Version: 1.4.6 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigC124095A8B251B81FB2A37C7" X-Virus-Scanned: clamav-milter 0.97.6 at lucid-nonsense.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on lucid-nonsense.infracaninophile.co.uk X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Dec 2012 09:57:27 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigC124095A8B251B81FB2A37C7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 23/12/2012 09:43, Polytropon wrote: > On Sun, 23 Dec 2012 10:34:34 +0100, Polytropon wrote: >> First, the lines with "read" have to be: >> >> cat /foo/bar.txt | while read $LINE1 >> >> cat /foo/bar/foo/bar.txt | while read $LINE2 >> >> Reason: $LINE1 and $LINE2 will be evaluated here, they are "empty >> string", causing "read" to throw an error. >=20 > Excuse me - I made a mistake! Of course those two lines > have to be: >=20 > cat /foo/bar.txt | while read LINE1 >=20 > and >=20 > cat /foo/bar/foo/bar.txt | while read LINE2 >=20 > The $ infront of the variable names have to be removed. > The variable _name_, not its content, has to be provided > to "read" as a parameter. >=20 > The script so far: >=20 >=20 >=20 > #!/bin/sh >=20 > cat foo.txt | while read LINE1 > do > cat bar.txt | while read LINE2 > do > if [ "$LINE1" =3D "$LINE2" ]; then > sw=3D"1" > echo "Current value of sw is : " $sw > break > fi > done > echo "Value of sw is : " $sw > if [ "$sw" =3D "0" ]; then > echo "DO SOMETHING!" > fi > sw=3D"0" > done >=20 >=20 Hmmm.... I'd just like to draw your attention to the comm(1) program, which lets you find lines common to two files, or only in one or other of a pair of inputs, very easily. The only slight gotcha is that the input files have to be sorted. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. PGP: http://www.infracaninophile.co.uk/pgpkey --------------enigC124095A8B251B81FB2A37C7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.16 (Darwin) Comment: Using GnuPG with undefined - http://www.enigmail.net/ iEYEARECAAYFAlDW1XgACgkQ8Mjk52CukIznsgCfeNgcDOOs3P6s0I4CHwIDxa/a XLMAniDdI2fw/aOgII/FUIkiAa4olr4j =cMR0 -----END PGP SIGNATURE----- --------------enigC124095A8B251B81FB2A37C7--