Re: Can you help about script
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:001Name A AddressA1AddressA2 PhoneA FileNo:002Name B AddressB1AddressB2 PhoneB FileNo:003Name C AddressC1AddressC2 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) } } ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Can you help about script
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:001Name A AddressA1AddressA2 PhoneA FileNo:002Name B AddressB1AddressB2 PhoneB FileNo:003Name C AddressC1AddressC2 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 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"