From owner-freebsd-questions@FreeBSD.ORG Fri Dec 10 08:47:50 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8A50D16A4CE for ; Fri, 10 Dec 2004 08:47:50 +0000 (GMT) Received: from hosea.tallye.com (joel.tallye.com [216.99.199.78]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9F12043D55 for ; Fri, 10 Dec 2004 08:47:49 +0000 (GMT) (envelope-from lorenl@alzatex.com) Received: from hosea.tallye.com (hosea.tallye.com [127.0.0.1]) by hosea.tallye.com (8.12.8/8.12.10) with ESMTP id iBA8lnYs015724 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 10 Dec 2004 00:47:49 -0800 Received: (from sttng359@localhost) by hosea.tallye.com (8.12.8/8.12.10/Submit) id iBA8lmbc015722; Fri, 10 Dec 2004 00:47:48 -0800 X-Authentication-Warning: hosea.tallye.com: sttng359 set sender to lorenl@alzatex.com using -f Date: Fri, 10 Dec 2004 00:47:48 -0800 From: "Loren M. Lang" To: "Thiyagarajan, Jemima" Message-ID: <20041210084748.GH32126@alzatex.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i X-GPG-Key: ftp://ftp.tallye.com/pub/lorenl_pubkey.asc X-GPG-Fingerprint: B3B9 D669 69C9 09EC 1BCD 835A FAF3 7A46 E4A3 280C cc: freebsd-questions@freebsd.org cc: jemydpm@yahoo.co.in Subject: Re: comparing two files yy.unl and xx.dat X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Dec 2004 08:47:50 -0000 On Thu, Dec 09, 2004 at 03:39:20PM -0500, Thiyagarajan, Jemima wrote: > Hi all > > I am new to shell scripts. I have a doubt. Please somebody help me. > > Any explanation with example will be appreciated. > > I try to compare 2 files xx.dat (data separated by comma) and yy.unl > (data separated by |). > > And if a record in xx.dat is not found in yy.unl then move that record > to some database table like db2 table. You could use cut on one file to seperate each field to a seperate file, then use paste to put it back together with the right seperator. After that sort both files and the run a diff, grepping for only deleted lines of one file: man cut man paste man sort man diff man grep $ cat xx.dat me,20,aax you,32,fds them,12,wsx $ cat yy.unl us|45|wrt me|20|aax them|12|wsx $ cut -d'|' -f1 yy.unl > field1 $ cut -d'|' -f2 yy.unl > field2 $ cut -d'|' -f3 yy.unl > field3 $ paste -d, field1 field2 field3 | sort > tmp $ cat xx.dat | sort | diff - tmp | grep '^<' | cut -d' ' -f2 > db2 $ cat db2 you|32|fds $ diff xx.dat db2 | grep '^<' | cut -d' ' -f2 > new-xx.dat $ mv new-xx.dat xx.dat $ cat xx.dat me,20,aax them,12,wsx But perhaps sed, awk or perl would be better. > > > > Thanks > > > > Jemima > > > > > > > ----------------------------------------- > This message and its contents (to include attachments) are the property of > Kmart Corporation (Kmart) and may contain confidential and proprietary > information. You are hereby notified that any disclosure, copying, or > distribution of this message, or the taking of any action based on > information contained herein is strictly prohibited. Unauthorized use of > information contained herein may subject you to civil and criminal > prosecution and penalties. If you are not the intended recipient, you > should delete this message immediately. > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" -- I sense much NT in you. NT leads to Bluescreen. Bluescreen leads to downtime. Downtime leads to suffering. NT is the path to the darkside. Powerful Unix is. Public Key: ftp://ftp.tallye.com/pub/lorenl_pubkey.asc Fingerprint: B3B9 D669 69C9 09EC 1BCD 835A FAF3 7A46 E4A3 280C