The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help me clean this up scanner248 UNIX for Dummies Questions & Answers 1 10-15-2007 04:31 PM
Clean Text File kris01752 UNIX for Advanced & Expert Users 1 08-24-2006 02:48 PM
Clean file in single action djp Shell Programming and Scripting 1 06-19-2006 05:34 PM
/tmp clean up at reboot Silver11 SUN Solaris 2 03-07-2006 01:08 AM
Clean an LV out of the ODM Wamland UNIX for Advanced & Expert Users 0 11-23-2004 04:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-27-2006
kris01752 kris01752 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 17
Clean File

BeginDate 07/01/06
End: 07/31/06
Cust: A02991 - Burnham
0002000 5,829,773 145.3
0009701 4,043,850 267.3
2005000 286,785.13 100.0


BeginDate 07/01/06
End: 07/31/06
Cust: A01239 - East Track PSE
Index A
0009902 317,356.82 890.2
0020021 94,694.23 90989.1


BeginDate 07/01/06
End: 07/31/06
Cust: A04067 - Fidelity Growth
investement
0009902 1,063,852 2990.3
0020021 699,709.35 4590.3


Above is my incoming file format.
I need to create a file with 6 columns( BeginDate,EndDate,Cust and the three associated columns with each Customer).The customer record
some times may be shown as 2 records.I need to make as one record.

I am kind of lost how to solve
  #2 (permalink)  
Old 09-27-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
can you show us the output you needed?
  #3 (permalink)  
Old 09-27-2006
kris01752 kris01752 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 17
Begin End Cust: Col1 Col2 Col3
07/01/06 07/31/06 A02991 - Burnham 0002000 5,829,773 145.3
07/01/06 07/31/06 A02991 - Burnham 0009701 4,043,850 267.3
07/01/06 07/31/06 A02991 - Burnham 2005000 286,785.13 100.0


This is how i need the output.
  #4 (permalink)  
Old 09-27-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
awk ' 
/BeginDate/ {
getline end_dt
getline cust
getline cust1
sub(".* ","",$0)
bgn_dt=$0
sub(".*: ","",end_dt)
sub(".*: ","",cust)
if ( match ( cust1 , "^[0-9][0-9]*" ) )
        print $0 " " end_dt " " cust " " cust1
else
{
        cust = cust cust1
}
}
/^[0-9]+/{
print bgn_dt " " end_dt " " cust " " $0 }' file
  #5 (permalink)  
Old 09-27-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
here's a slightly different approach:

nawk -f kris.awk myFile.txt

kris.awk:
Code:
BEGIN {
  FS=RS=""
}

{
   head=sprintf("%s%s", substr($1, index($1, " ")+1), OFS)
   head=head sprintf("%s%s", substr($2, index($2, " ")+1), OFS)
   head=head sprintf("%s%s", substr($3, index($3, " ")+1), OFS)
   for(f=4; f<=NF; f++)
      if( $f ~ /^[0-9]/ )
         printf("%s%s\n", head, $f)
}
  #6 (permalink)  
Old 09-28-2006
kris01752 kris01752 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 17
Thank you for the help
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0