Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help converting and formatting file

Status
Not open for further replies.

nguyenb9

Technical User
Apr 1, 2003
55
US
I have an input file, and I want to format a file as follows:

EXAMPLE OF INPUT FILE:

DAL-Hill|609|43675594|DALWORTH CARPET CLEANING|51|05/12/1995|88|
DAL-Hill|738|43770664|AUTISTIC TREATMENT CENTERS|51|02/22/2002|54|
HOU-Taggart|391|43772688|NATIONS BANKER MORTGAGE|61|08/14/2002|65|
HOU-Taggart|645|43315076|EXECUTIVES|61|06/20/1990|88|
Spare 6|1|43758585|CHECKCARE|995|11/05/1999|64|
Spare 6|1|43501253|PAN AMERICAN VETERINARY LABORATORIES|995|03/30/1993|88|
Spare 6|1|43761279|STRATEGY GOV|995|02/23/2001|66|
TUL-Dick|557|43775324|WOODLAND HILLS MALL, LLC|29|03/06/2003|54

Result should look like:

Company Name
The Report
Page 1 of 1


Office Sale Arm Opendate
Name ID account_id acct_lname ID Acct acct_type
****** **** ********** ********** **** ******** *********
DAL-Hill 609 43675594 DALWORTH CARPET CLEANING 51 1995-05-12 88 DAL-Hill 738 43770664 AUTISTIC TREATMENT CENTERS 51 2002-02-22 54 HOU-Taggart 391 43772688 NATIONS BANKER MORTGAGE 61 2002-08-14 65 HOU-Taggart 645 43315076 EXECUTIVES 61 1990-06-20 88 Spare 6 1 43758585 CHECKCARE 995 1999-11-05 64 Spare 6 1 43501253 PAN AMERICAN VETERINARY 995 1993-03-30 88 Spare 6 1 43761279 STRATEGY GOV 995 2001-02-23 66 TUL-Dick 557 43775324 WOODLAND HILLS MALL, LLC 29 2003-03-06 54

If you can provide with the awk program

thank you

 
If you would try first I'd be more willing to help you.
Here's a start, I won't work too hard on this.

Code:
BEGIN {
printf("%s \t%s \t%s \t%s \t%s \t%s \t%s\n\n", "Office Name","SaleId", "AccountID", "Acct_lname","OPendate","ID","Acct_type")
FS="|" ; OFS="\t"
}

{
      for (i=1 ; i <= 7 ; i++) {
           if ((v = match($i,/[\t ]/)) > 0) {
              sub(/[\t  ]/,&quot;-&quot;,$i)
           }
           printf(&quot;%s\t&quot;,$i)
      }
      printf(&quot;\n&quot;)
     
}

 
I made some modification on the script but the report did not line up evenly on the column.

Here is modification script:

BEGIN {
printf &quot; Company Name\n &quot;
printf &quot; Report name \n\n&quot;
printf(&quot;%s \t%s \t%s \t%s \t%s \t%s \t%s\n&quot;, &quot;Office Name&quot;,&quot;SaleId&quot;, &quot;AccountID&quot;, &quot;Acct_lname&quot;,&quot; A
rmID&quot;,&quot;OPendate&quot;,&quot;Acct_type&quot;)
printf &quot;---------- ------ --------- ---------- ----- -------- -------\n
&quot;
FS=&quot;|&quot; ; OFS=&quot;\t&quot;
}

{
for (i=1 ; i <= 7 ; i++) {
if ((v = match($i,/[\t ]/)) > 0) {
sub(/[\t ]/,&quot;-&quot;,$i)
}
printf(&quot;%s\t&quot;,$i)
}
printf(&quot;\n&quot;)


Output:

Company Name
Report name

Office Name SaleId AccountID Acct_lname ArmID OPendate Acct_type
---------- ------ --------- ---------- ----- -------- -------
DAL-Hill 609 43675594 DALWORTH-CARPET CLEANING 51 05/12/1995 88
DAL-Hill 738 43770664 AUTISTIC-TREATMENT CENTERS 51 02/22/2002 54
HOU-Taggart 391 43772688 NATIONS-BANKER MORTGAGE 61 08/14/2002 65
HOU-Taggart 645 43315076 EXECUTIVES 61 06/20/1990 88
Spare-6 1 43758585 CHECKCARE 995 11/05/1999 64
Spare-6 1 43501253 PAN-AMERICAN VETERINARY LABORATORIES 995 03/30/1993 88
Spare-6 1 43761279 STRATEGY-GOV 995 02/23/2001 66
TUL-Dick 557 43775324 WOODLAND-HILLS MALL, LLC 29 03/06/2003 54

Thank for your help


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top