Date: Wed, 14 Nov 2007 21:46:46 +0100 From: Tino Engel <elrap@web.de> To: ann kok <annkok2001@yahoo.com> Cc: freebsd-questions@freebsd.org Subject: Re: Can you help about script Message-ID: <473B5EB6.3020609@web.de> In-Reply-To: <295004.76329.qm@web53304.mail.re2.yahoo.com> References: <295004.76329.qm@web53304.mail.re2.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <yourfile> 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) } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?473B5EB6.3020609>