From owner-freebsd-questions@FreeBSD.ORG Wed Nov 14 20:30:22 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 09E2816A474 for ; Wed, 14 Nov 2007 20:30:22 +0000 (UTC) (envelope-from jamesh@lanl.gov) Received: from mailwasher.lanl.gov (mailwasher.lanl.gov [204.121.3.2]) by mx1.freebsd.org (Postfix) with ESMTP id C810B13C45B for ; Wed, 14 Nov 2007 20:30:20 +0000 (UTC) (envelope-from jamesh@lanl.gov) Received: from mailrelay3.lanl.gov (mailrelay3.lanl.gov [128.165.4.104]) by mailwasher.lanl.gov (8.13.8/8.13.8/(ccn-5)) with ESMTP id lAEKUH0x028807; Wed, 14 Nov 2007 13:30:17 -0700 Received: from oppie-mail.lanl.gov (oppie-mail.lanl.gov [128.165.4.123]) by mailrelay3.lanl.gov (8.13.8/8.13.8/(ccn-5)) with ESMTP id lAEKUGBn030988; Wed, 14 Nov 2007 13:30:16 -0700 Received: from p25dual1.lanl.gov (p25dual1.lanl.gov [128.165.86.60]) by oppie-mail.lanl.gov (Postfix) with ESMTP id D48231F8005; Wed, 14 Nov 2007 13:30:12 -0700 (MST) X-Mailer: QUALCOMM Windows Eudora Version 7.1.0.9 Date: Wed, 14 Nov 2007 13:30:12 -0700 To: ann kok , freebsd-questions@freebsd.org From: James In-Reply-To: <295004.76329.qm@web53304.mail.re2.yahoo.com> References: <295004.76329.qm@web53304.mail.re2.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Message-Id: <20071114203012.D48231F8005@oppie-mail.lanl.gov> X-CTN-5-MailScanner-Information: Please see http://network.lanl.gov/email/virus-scan.php X-CTN-5-MailScanner: Found to be clean X-CTN-5-MailScanner-From: jamesh@lanl.gov X-Spam-Status: No Cc: Subject: Re: Can you help about script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Nov 2007 20:30:22 -0000 At 12:07 PM 11/14/2007, ann kok wrote: >Hi all > >I don't have idea how to write this script, please >help > >I have thousand records in this format indexed by >FileNo. > >FileNo: 001 >Name: NameA >Address1: AddressA1 >Address2: AddressA2 >Phone: PhoneA >Created by > > >I need to write a script to replace those Fields >eg: (NameA AddressA1.... if it matchs the >FileNo.001...002...) >to get Data in this file > > >FileNo:001 Name A AddressA1 AddressA2 >PhoneA >FileNo:002 Name B AddressB1 AddressB2 >PhoneB >FileNo:003 Name C AddressC1 AddressC2 >PhoneC > >Thank you for your help > Do you have any restrictions with regards to language? There are a few things that come to mind; if this is absolutely indexed how you stated, with no problems of extra blank lines etc existing, you could use line to read in the lines one at a time, use a simple grep/case statement to check whether the initial field conforms to a specific string, and assign each string to a variable. After six read ins, you have all the information you need and you ouput them however you want. James