Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Dec 2012 09:57:02 +0000
From:      Matthew Seaman <matthew@FreeBSD.org>
To:        freebsd-questions@freebsd.org
Subject:   Re: shell script problem
Message-ID:  <50D6D56E.8000401@FreeBSD.org>
In-Reply-To: <20121223104311.557f3752.freebsd@edvax.de>
References:  <1356253535.76738.YahooMailClassic@web160101.mail.bf1.yahoo.com> <20121223103434.def7cd9c.freebsd@edvax.de> <20121223104311.557f3752.freebsd@edvax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50D6D56E.8000401>