parse coloum in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parse coloum in a file
# 1  
Old 04-29-2008
Question parse coloum in a file

I have a file like the format

0000023716272400000237162724555778180300000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000001099001099425%00109925%IPY 2007013120070227Y99991231N YYX SRT0001010125%0000503318882HANDH800 R
0000023716282300000237162823555765956000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000001099001099425%00109925%IPY 2007013100010101Y99991231N YYX SRT0001010125%0000503418302HANDH800 R
0000030805382100000308053821555002938300000010000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000001699001699Q39%00169939%IP 2000093020000905N00010101N NYXNNNSRT0001010139%0000200601622PMPP6007 Y Z

here i copy and past my code

#############################################
# Parse File
#############################################
cut -c2-14 /var/www/html/final_java/IngramHourlyFile/stock@ingram.dat|awk '{print "where isbn=|"$1"|"}'|tr "|" "'">/var/www/html/final_java/IngramHourlyFile/isbn.dat
cut -c39-45 /var/www/html/final_java/IngramHourlyFile/stock@ingram.dat|awk '{print "UPDATE item_details SET ib_N_qty="$1}'>/var/www/html/final_java/IngramHourlyFile/OHQTY_N.dat
cut -c46-52 /var/www/html/final_java/IngramHourlyFile/stock@ingram.dat|awk '{print "ib_E_qty="$1}'>/var/www/html/final_java/IngramHourlyFile/OHQTY_E.dat
cut -c53-59 /var/www/html/final_java/IngramHourlyFile/stock@ingram.dat|awk '{print "ib_D_qty="$1}'>/var/www/html/final_java/IngramHourlyFile/OHQTY_D.dat
cut -c60-66 /var/www/html/final_java/IngramHourlyFile/stock@ingram.dat|awk '{print "ib_C_qty="$1}'>/var/www/html/final_java/IngramHourlyFile/OHQTY_C.dat
cut -c151-156 /var/www/html/final_java/IngramHourlyFile/stock@ingram.dat|awk '{print "iblastupdate=NOW(),ib_qty=(ib_E_qty+ib_N_qty+ib_D_qty+ib_C_qty),ib_listprice="$1"/100"}'>/var/www/html/final_java/IngramHourlyFile/PRICE.dat
cut -c164-166 /var/www/html/final_java/IngramHourlyFile/stock@ingram.dat|awk '{print "ib_discode=|"$1"|"}'|tr "|" "'">/var/www/html/final_java/IngramHourlyFile/DISCODE.dat

############################################
# Change File permission
############################################

chmod 777 /var/www/html/final_java/IngramHourlyFile/isbn.dat
chmod 777 /var/www/html/final_java/IngramHourlyFile/OHQTY_N.dat
chmod 777 /var/www/html/final_java/IngramHourlyFile/OHQTY_E.dat
chmod 777 /var/www/html/final_java/IngramHourlyFile/OHQTY_D.dat
chmod 777 /var/www/html/final_java/IngramHourlyFile/OHQTY_C.dat
chmod 777 /var/www/html/final_java/IngramHourlyFile/PRICE.dat
chmod 777 /var/www/html/final_java/IngramHourlyFile/DISCODE.dat

paste -d"," /var/www/html/final_java/IngramHourlyFile/OHQTY_N.dat /var/www/html/final_java/IngramHourlyFile/OHQTY_E.dat /var/www/html/final_java/IngramHourlyFile/OHQTY_D.dat /var/www/html/final_java/IngramHourlyFile/OHQTY_C.dat /var/www/html/final_java/IngramHourlyFile/PRICE.dat /var/www/html/final_java/IngramHourlyFile/DISCODE.dat>/var/www/html/final_java/IngramHourlyFile/tmpfinal_isbn.dat

chmod 777 /var/www/html/final_java/IngramHourlyFile/tmpfinal_isbn.dat

paste -d" " /var/www/html/final_java/IngramHourlyFile/tmpfinal_isbn.dat /var/www/html/final_java/IngramHourlyFile/isbn.dat>/var/www/html/final_java/IngramHourlyFile/tfinal_isbn.dat

chmod 777 /var/www/html/final_java/IngramHourlyFile/tfinal_isbn.dat

paste -d";" /var/www/html/final_java/IngramHourlyFile/tfinal_isbn.dat /var/www/html/final_java/IngramHourlyFile/single_quote.dat>/var/www/html/final_java/IngramHourlyFile/final_isbn.dat

chmod 777 /var/www/html/final_java/IngramHourlyFile/final_isbn.dat

It takes too long time because the file size is too big.I have to do it with in 15 min.

please help me.

thanks!
vaskar
# 2  
Old 04-29-2008
not sure if this will increase performance by a significant amuont but you could always copy those files to the /tmp dir and read from there. also, a suggestion for you. when you have a dir that is common in your code, i would write it once to help others and you read your script a little easier:
Code:
#############################################
# Parse File
#############################################
dir=/var/www/html/final_java/IngramHourlyFile

cut -c2-14 $dir/stock@ingram.dat|awk '{print "where isbn=|"$1"|"}'|tr "|" "'">$dir/isbn.dat
cut -c39-45 $dir/stock@ingram.dat|awk '{print "UPDATE item_details SET ib_N_qty="$1}'>$dir/OHQTY_N.dat
cut -c46-52 $dir/stock@ingram.dat|awk '{print "ib_E_qty="$1}'>$dir/OHQTY_E.dat
cut -c53-59 $dir/stock@ingram.dat|awk '{print "ib_D_qty="$1}'>$dir/OHQTY_D.dat
cut -c60-66 $dir/stock@ingram.dat|awk '{print "ib_C_qty="$1}'>$dir/OHQTY_C.dat
cut -c151-156 $dir/stock@ingram.dat|awk '{print "iblastupdate=NOW(),ib_qty=(ib_E_qty+ib_N_qty+ib_D_qty+ib_C_qty),ib_listprice="$1"/100"}'>$dir/PRICE.dat
cut -c164-166 $dir/stock@ingram.dat|awk '{print "ib_discode=|"$1"|"}'|tr "|" "'">$dir/DISCODE.dat

# 3  
Old 04-29-2008
This is a good example of Useless Use of cut, tr , chmod, paste and temp files when you can use only awk.
Code:
#cat awk.code
{
a="UPDATE item_details SET ib_N_qty="substr($0,39,7)
b="ib_E_qty="substr($0,46,7)
c="ib_D_qty="substr($0,53,7)
d="ib_C_qty="substr($0,60,7)
e="iblastupdate=NOW(),ib_qty=(ib_E_qty+ib_N_qty+ib_D_qty+ib_C_qty),ib_listprice="substr($0,151,6)"/100"
f="ib_discode=\47"substr($0,164,3)"\47"
g="where isbn=\47" substr($0,2,13)"\47"
print a","b","c","d","e","f" "g";"
}

And now run the code.
Code:
awk -f awk.code data.file > sql.file


Last edited by danmero; 04-29-2008 at 12:01 PM.. Reason: Typo
# 4  
Old 04-30-2008
Thanks! Smilie it is working....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to parse a file?

Hi guys I have a very long file which looks like this: y893 89:send prctmgr exit 106:bas_services_dwn -------------------------------------------------- y895 90:send prctmgr exit 106:bas_services_dwn -------------------------------------------------- y897 90:send prctmgr exit... (3 Replies)
Discussion started by: aoussenko
3 Replies

2. Shell Programming and Scripting

parse fasta file to tabular file

Hello, A bioperl problem I thought could be done with awk: convert the fasta format (Note: the length of each row is not the same for each entry as they were combined from different files!) to tabular format. input.fasta: >YAL069W-1.334 Putative promoter sequence... (6 Replies)
Discussion started by: yifangt
6 Replies

3. Shell Programming and Scripting

Parse a file

FILE1 2917,065A,RDF1+TDEV,2917_3RAID5,05E:0_10E:0,BL_lmwsp02,0345,xxx,3452(DR) 2917,03EA,RDF1+TDEV,2917_3RAID5,03E:0_12E:0,BL_tv00p02,0455,xxx,3ee4(DR) 2917,03EB,RDF1+TDEV,2917_3RAID5,03E:0_12E:0,BL_tv00p02,0345,xxx,2d34(DR)... (7 Replies)
Discussion started by: greycells
7 Replies

4. Shell Programming and Scripting

Parse file from remote server to calculate count of string existence in that file

Hi I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files. Say a file abc.log exist on 2 servers. I want to search for string "test" on both files and calculate the total count of search string's existence. For... (6 Replies)
Discussion started by: poweroflinux
6 Replies

5. Shell Programming and Scripting

add coloum value based on first coloum

Hi i have a file and i want to add the coloum values like 9067 is coming twice here so o/p willbe like 9067,sum of 3rd coloum,sum of 4th coloum 9015 is coming 0nce then o/p 9015,15,6 sum is happening based on first coloum it will add all the third coloum and 4th coloum value where first... (1 Reply)
Discussion started by: aaysa123
1 Replies

6. Shell Programming and Scripting

compare 2 coloum of 2 diff files using perl script

Hi, i am new to perl scripting.. i am still learing it.. i am asked to write a perl script which should compare 2 coloums of 2 different files. if those 2 coloumn are same the script should store the both the lines in 2 diff files. these are files, file 1: 21767016 226112 char 19136520... (3 Replies)
Discussion started by: vasuki
3 Replies

7. UNIX for Advanced & Expert Users

How to parse through a file and based on condition form another output file

I have one file say CM.txt which contains values like below.Its just a flat file 1000,A,X 1001,B,Y 1002,B,Z ... .. total around 4 million lines of entries will be in that file. Now i need to write another file CM1.txt which should have 1000,1 1001,2 1002,3 .... ... .. Here i... (6 Replies)
Discussion started by: sivasu.india
6 Replies

8. Shell Programming and Scripting

Need help to parse the file

# Start "ABC" SFFd 0 4 Time SFFT 4 8 {Sec} User SFFTimeVal 12 8 {Sec} # Start "CP" SFFT ... (3 Replies)
Discussion started by: navsharan
3 Replies

9. Shell Programming and Scripting

Parse file

Hi Friends, I have a file in the format shown (Name followed by address:) I need only the address part please see the output. I have tried using nawk but I am not getting the desired output. SAM ADDRS 64874 FRANKLYN DR IRVINE TX - 74394; 538 FRED ASSOCIATES PETER ADDRS 84734... (5 Replies)
Discussion started by: sbasetty
5 Replies

10. Shell Programming and Scripting

how to insert new coloum

Dear friends, I have a dataset like this 2.18 66.86 27.9 2.18 66.86 27.9 2.18 66.86 27.9 2.15 66.88 27.9 2.15 66.88 27.9 Now i have another dataset containing date coloum like this 22-12-2005 22-12-2005 22-12-2005 22-12-2005 22-12-2005 Now i want to... (3 Replies)
Discussion started by: rajan_ka1
3 Replies
Login or Register to Ask a Question