From owner-freebsd-questions@FreeBSD.ORG Wed Nov 14 20:47:48 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 98EAD16A41B for ; Wed, 14 Nov 2007 20:47:48 +0000 (UTC) (envelope-from elrap@web.de) Received: from fmmailgate02.web.de (fmmailgate02.web.de [217.72.192.227]) by mx1.freebsd.org (Postfix) with ESMTP id 5383013C467 for ; Wed, 14 Nov 2007 20:47:48 +0000 (UTC) (envelope-from elrap@web.de) Received: from smtp08.web.de (fmsmtp08.dlan.cinetic.de [172.20.5.216]) by fmmailgate02.web.de (Postfix) with ESMTP id 5DD53AED0B3D; Wed, 14 Nov 2007 21:47:15 +0100 (CET) Received: from [84.152.175.120] (helo=freebsdangel.de) by smtp08.web.de with asmtp (WEB.DE 4.108 #208) id 1IsP8l-00004w-00; Wed, 14 Nov 2007 21:47:15 +0100 Message-ID: <473B5EB6.3020609@web.de> Date: Wed, 14 Nov 2007 21:46:46 +0100 From: Tino Engel User-Agent: Thunderbird 2.0.0.6 (X11/20071110) MIME-Version: 1.0 To: ann kok References: <295004.76329.qm@web53304.mail.re2.yahoo.com> In-Reply-To: <295004.76329.qm@web53304.mail.re2.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: elrap@web.de X-Sender: elrap@web.de X-Provags-ID: V01U2FsdGVkX18qPHxE2Sseim32MjWtixUECW3b9YdKbcsAeGpX wKeOVTjmaQEiPYEEhKuRJqoOV/kMfzUdY7KIiCAC6KI1o6azG8 tpr7eCCv0= Cc: freebsd-questions@freebsd.org 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:47:48 -0000 ann kok schrieb: > 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 > > > It is definetely an issue for the 'awk' utility. Here is a working solution, although it could be done somehow shorter using patterns (I do not recall how they worked. But I have tested this one, it does the job. #awk -f prog.awk prog.awk should contain: { if( $1 == "FileNo:") { printf( "%s%s ", $1 , $2) } if( $1 == "Name:") { printf( "%s ", $2) } if( $1 == "Address1:") { printf( "%s ", $2) } if( $1 == "Address2:") { printf( "%s", $2) } if( $1 == "Phone:") { printf( "\n%s\n", $2) } }