Get the data in my required form using gawk

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Get the data in my required form using gawk
# 1  
Old 12-18-2009
CPU & Memory Get the data in my required form using gawk

i had the data in the following form:
Branch : 3379 As On : 31-JAN-2009 Page : 1
User Id : OPER1 Date & Time : 01-FEB-2009 04:02:37

------------------------------------------------------------------------------------------------------------------------------------
Period JAN LCY Amount FCY Amount (LCY Eq) Total

------------------------------------------------------------------------------------------------------------------------------------
Asset

220120100 BALANCE IN C/A-WITH SBI 18,375.58 0.00 18,375.58
220720200 INTEREST RECEIVABLE - JL 0.00 0.00 0.00
220720400 INTEREST RECEIVABLE - OSL 69,564.99 0.00 69,564.99

with Branch:3379 and As on : 31-jan-2009 at the top of the report......

The report contained 5 columns.......

what i want is to have 7 columns of only data (without header and footer)....first column should be the Branch code ie., 3379; second
column should be the date of the report ie., 31-jan-2009 and rest of the
data in the order of 1,2,3,4, and 5th columns in the place of 3,4,5,6, and 7th columns......
Example:
3379 31-jan-2009 220120100 BALANCE IN C/A-WITH SBI 18,375.58 0.00 18,375.58

pl.. help by providing suitable gwak command....
# 2  
Old 12-18-2009
Quote:
Originally Posted by KANNI786
i had the data in the following form:
Branch : 3379 As On : 31-JAN-2009 Page : 1
User Id : OPER1 Date & Time : 01-FEB-2009 04:02:37

------------------------------------------------------------------------------------------------------------------------------------
Period JAN LCY Amount FCY Amount (LCY Eq) Total

------------------------------------------------------------------------------------------------------------------------------------
Asset

220120100 BALANCE IN C/A-WITH SBI 18,375.58 0.00 18,375.58
220720200 INTEREST RECEIVABLE - JL 0.00 0.00 0.00
220720400 INTEREST RECEIVABLE - OSL 69,564.99 0.00 69,564.99

with Branch:3379 and As on : 31-jan-2009 at the top of the report......

The report contained 5 columns.......

what i want is to have 7 columns of only data (without header and footer)....first column should be the Branch code ie., 3379; second
column should be the date of the report ie., 31-jan-2009 and rest of the
data in the order of 1,2,3,4, and 5th columns in the place of 3,4,5,6, and 7th columns......
Example:
3379 31-jan-2009 220120100 BALANCE IN C/A-WITH SBI 18,375.58 0.00 18,375.58

pl.. help by providing suitable gwak command....
Plz tell what have you tried so far..
# 3  
Old 12-19-2009
sir.. thank u for calling

i tried the following to get the data under the following heads
branch date code total
3379 31012009 220120100 18,375.58
3379 31012009 220720200 0.00
3379 31012009 220720400 69,564.99
3379 31012009 220720600 77,843.76

i could not succeed, the change of character position did not result in
any data...
Code:
                          
{
a=b=0
a=index($0,"Branch  : ")
b=index($0,"As On       :    ")
if ( a > 0 )
   { bic=substr($0,length($0)11,4)
     next
   }
if ( b > 0 )
   { split(substr($0,63,11),datee,"-")
     if ( datee[2]=="jan")
        { mm=01
 }
     if ( datee[2]=="feb")
        { mm=02
 }
     if ( datee[2]=="mar")
        { mm=03
 }
     if ( datee[2]=="apr")
        { mm=04
 }
     if ( datee[2]=="may")
        { mm=05
 }
     if ( datee[2]=="jun")
        { mm=06
 }
     if ( datee[2]=="jul")
        { mm=07
 }
     if ( datee[2]=="aug")
        { mm=08
 }
     if ( datee[2]=="sep")
        { mm=09
 }
     if ( datee[2]=="oct")
        { mm=10
 }
     if ( datee[2]=="nov")
        { mm=11
 }
     if ( datee[2]=="dec")
        { mm=12
 }
     date1=sprintf("%02d%02d%04d",datee[1],mm,datee[3])
     next
   }
ctr=split($0,arr," ")
amt=kod=0
if (ctr > 1)
 {
  for (i=1;i<(ctr+1);i++)
    { 
      if (index(arr[i],".") > 0 )
         { 
           gsub(",","",arr[i])
           gsub("\\.","",arr[i])
           gsub("-","",arr[i])
         }
    }
  for (i=1;i<ctr;i++)
    { 
      if ( (arr[i]    ~ /^[0-9]+$/) && ( arr[i+1] ~ /^[0-9]+$/))
         {
     kod=arr[i]+0
     amt=arr[i+1]+0
            i++
  }
    }
  if ( kod > 100000000 && kod < 999999999 && amt > 0 )
     {
            printf("%04d%08d%09d%013.0f\n",bic,date1,kod,amt*1)                    
     kod=amt=0
     }
    
 }
}



---------- Post updated at 06:44 PM ---------- Previous update was at 06:17 PM ----------

Quote:
Originally Posted by gaurav1086
Plz tell what have you tried so far..
sir.. thank u for calling

i tried the following to get the data under the following heads
branch date code total
3379 31012009 220120100 18,375.58
3379 31012009 220720200 0.00
3379 31012009 220720400 69,564.99
3379 31012009 220720600 77,843.76

i could not succeed, the change of character position did not result in
any data...


Code:
{a=b=0a=index($0,"Branch : ")b=index($0,"As On : ")if ( a > 0 ) { bic=substr($0,length($0)11,4) next }if ( b > 0 ) { split(substr($0,63,11),datee,"-") if ( datee[2]=="jan") { mm=01 } if ( datee[2]=="feb") { mm=02 } if ( datee[2]=="mar") { mm=03 } if ( datee[2]=="apr") { mm=04 } if ( datee[2]=="may") { mm=05 } if ( datee[2]=="jun") { mm=06 } if ( datee[2]=="jul") { mm=07 } if ( datee[2]=="aug") { mm=08 } if ( datee[2]=="sep") { mm=09 } if ( datee[2]=="oct") { mm=10 } if ( datee[2]=="nov") { mm=11 } if ( datee[2]=="dec") { mm=12 } date1=sprintf("%02d%02d%04d",datee[1],mm,datee[3]) next }ctr=split($0,arr," ")amt=kod=0if (ctr > 1) { for (i=1;i<(ctr+1);i++) { if (index(arr[i],".") > 0 ) { gsub(",","",arr[i]) gsub("\\.","",arr[i]) gsub("-","",arr[i]) } } for (i=1;i<ctr;i++) { if ( (arr[i] ~ /^[0-9]+$/) && ( arr[i+1] ~ /^[0-9]+$/)) { kod=arr[i]+0 amt=arr[i+1]+0 i++ } } if ( kod > 100000000 && kod < 999999999 && amt > 0 ) { printf("%04d%08d%09d%013.0f\n",bic,date1,kod,amt*1) kod=amt=0 } }}

Last edited by Scott; 12-19-2009 at 08:53 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetching the required data out of a tabular form

Hello Gurus, I am trying to fetch a required number of lines from an output of a command which is in tabular form. Below is the command for reference along with how the result is being shown on UNIX shell. /usr/openv/volmgr/bin/vmquery -b -p 5 The result of the above command is as... (6 Replies)
Discussion started by: Ali Sarwar
6 Replies

2. Shell Programming and Scripting

Need help in creating a file in required format form another existing file

I have a text file with contents like this: a,b,c, d~e,f,g,h~i,j ,k,l,m~n,o,p,q~ I need to convert this file into this format unix shell script commands: a,b,c,d~ e,f,g,h~ i,j,k,l,m~ n,o,p,q~ as you may have noticed, I need to retain the ~ signs at the end. Any help is greatly... (3 Replies)
Discussion started by: harsha1238
3 Replies

3. Shell Programming and Scripting

Getting data in table form

Hi, I have a csv file from which i am fetching few columns as below: IFILE=/home/home1/Report1.csv OFILE=/home/home1/`date +"%m%d%y%H%M%S"`.dat if #Checks if file exists and readable then awk -F "," '(NR>4) {print $1,$6,$2,$3,$4,$5,$6}' ${IFILE} >> ${OFILE} fi cat $OFILE | mail... (7 Replies)
Discussion started by: Vivekit82
7 Replies

4. Shell Programming and Scripting

Transpose Data form Different form

HI Guys, I have data in File A.txt RL03 RL03_A_1 RL03_B_1 RL03_C_1 RL03 -119.8 -119.5 -119.5 RL07 RL07_A_1 RL07_B_1 RL07_C_1 RL07 -119.3 -119.5 -119.5 RL15 RL15_A_1 RL15_C_1 RL15 -120.5 -119.4 RL16... (2 Replies)
Discussion started by: asavaliya
2 Replies

5. UNIX for Dummies Questions & Answers

Put data in tabular form..

Dear Friends, I have a file as under : +++ ME 12-06-13 18:16:20 A RED FEW AND ROW1 1MN FEL AS HI FI BV LR TS HR ES MR * 0 13296 0 120 1 15 KS RR 10 0 +++ ME 12-06-13 18:26:20 A RED FEW AND ROW2 1MN FEL AS... (2 Replies)
Discussion started by: vanand420
2 Replies

6. Shell Programming and Scripting

Reformatting data in matrix form

Hi, Some assistance with respect to the following problem will be very helpful. I want to reformat my dataset in the following manner for subsequent analysis. I have first column values (which repeat for each value of 2nd column) which are names, the second column specifies position ad the... (1 Reply)
Discussion started by: newbie83
1 Replies

7. UNIX for Dummies Questions & Answers

Posting data to a form using curl

Hello all. I have an incredible number of servers that I need to change a parameter on using a web interface. I'd like to be able to do this via curl, but I'm having some trouble. I filled out the form and hit update while snooping (tcpdump) my interface. That gave the the following as what is... (0 Replies)
Discussion started by: DeCoTwc
0 Replies

8. Shell Programming and Scripting

convert one form of xml data to other

I would like to convert one form of xml tag data to another <DescriptionList> <DescriptionExt language="en" shortDesc="ITALIAN SAUSAGE SUB" longDesc="" sizeDesc="" smallImage="Pictures\sub-italian-sausage.png" largeImage="" forceImageUpdate="yes" /> ... (1 Reply)
Discussion started by: saisus
1 Replies

9. UNIX for Dummies Questions & Answers

changing data into matrix form

Hi, I have a file whose structure is like this 7 7 1 2 3 4 5 1 3 4 8 6 1 4 5 6 0 2 6 8 3 8 2 5 7 8 0 5 7 9 4 1 3 8 0 2 2 3 5 6 8 basically first two row tell the number of rows and column but the data following them are not arranged in that format. now i want to create another... (1 Reply)
Discussion started by: g0600014
1 Replies

10. UNIX for Dummies Questions & Answers

data form

I am user Of linux 9.0 Operating System and I had data form unix Operating system and I am not abel to open it in linux 9.0 Please tell me how can i use unix data in linux . (3 Replies)
Discussion started by: harsh_guru
3 Replies
Login or Register to Ask a Question