Single and Double Quote Issue using GAWK - quotes

I have been helped with the following GAWK command line in Windows
gawk "{a = gensub(/([0-9]{6} [0-9]{6} [0-9]{4}).*itemId=, "\\2 \\1", "g", $0); b = split(a, c, " "); if (c[1] in result) result[c[1]] = gensub(/(.+),(.+)/, "\\1," c[2] " " c[3] " " c[4], "g", result[c[1]]); else result[c[1]] = c[2] " " c[3] " " c[4] "," c[2] " " c[3] " " c[4]} END { for (i in result) print i ": " result[i]}" Item.log
I have thousands of lines of text, like below which contain information for an item in ITEMID, these can be spread throughout the file, I want to get the first date and time and the last date and time and create a line like :
ITEMID 170209 003122 170209 003621
The date format about is YYMMDD HHMMSS
170209 003122 0893 DE(N) ItemHandler.ItemLog event=<VOLUME_RESULT>, *************************, itemId=<12551677>, globalId=<12551677>, cmcIndex=<973>, sorter=<0: MS01>, state=<CSC: WaitForData>, volumeId=<4104: MS01.IU05-VMS04>, volumeStatus=<0>, volScanResult=<0>, length=<665 mm>, width=<610 mm>, height=<470 mm>, volume=<190656000 mm3>, position=<sorter#0.volume#4104: MS01.IU05-VMS04>, volSystemId=<4>, volReferenceRecord=<2542>, volLevelOffset=<0>, volDataCrc=<48107>, itemRevisionNumber=<3> ##[
170209 003126 0210 DE(N) ItemHandler.ItemLog event=<SCANNER_RESULT>, ************************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForData>, barcodeCount=<1>, barcodes=<[ProxyWrapperBarcode(barcode=<T000042357>, type=<C0>, result=<OK>, ccType=<>)]>, codeSource=<ohscan>, scannerId=<4000: SCAN01>, scannerStatus=<0>, position=<sorter#0.scanner#4000: SCAN01>, itemRevisionNumber=<5> ##[
170209 003126 0210 DE(N) ItemHandler.ItemLog event=<DESTINATION_REQUEST>, *******************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForData>, barcodes=<[ProxyWrapperBarcode(barcode=<T000042357>, type=<C0>, result=<OK>, ccType=<>)]>, ccReason=<SCANNER_DATA_ADDED>, PreviousccResult=<>, sortSchemeId=<-1>, sortSchemeName=<>, logicalDestination=<>, BatchCountItem=<true>, collectionId=<-1>, goodsId=<>, position=<sorter#0.scanner#4000: SCAN01>, dynamicDataCount=<0>, dynamicData=<{}>, carrierId=<202>, carrierCount=<1>, itemRevisionNumber=<5> ##[
170209 003126 0225 DE(N) ItemHandler.ItemLog event=<DESTINATION_REPLY>, *********************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, ccReason=<SCANNER_DATA_ADDED>, PendingccResult=<OK>, Pendingstrategy=<notSpecified>, PendingchuteGroup=<[3000]: Parked0>, PendingNotChutedestinationId=<-1>, PendingsortSchemeId=<-1>, PendingsortSchemeName=<>, PendinglogicalDestination=<>, PendinggoodsId=<>, PendingBatchCountItem=<true>, PendingcollectionId=<-1>, position=<sorter#0.scanner#4000: SCAN01>, dynamicDataCount=<0>, dynamicData=<{}>, itemRevisionNumber=<7> ##[
170209 003126 0225 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM>, *************************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, PendingchuteGroup=<[3000]: Parked0>, Pendingstrategy=<notSpecified>, CscdestinationId=<-1: UnDef>, CmcdestinationId=<4099: All Scanners>, position=<sorter#0.scanner#4000: SCAN01>, itemRevisionNumber=<7> ##[
170209 003126 0454 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM_REPLY>, *******************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, CscdestinationId=<3000: Parked0>, chuteGroup=<[3000]: Parked0>, CmcdestinationId=<3000: Parked0>, position=<sorter#0.scanner#4000: SCAN01>, chuteListStartPoint=<-1>, itemRevisionNumber=<9> ##[
170209 003126 0456 DE(N) ItemHandler.ItemLog event=<RECONVERT>, *****************************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForData>, CscdestinationId=<3000: Parked0>, chuteGroup=<[3000]: Parked0>, CmcdestinationId=<3000: Parked0>, position=<sorter#0.scanner#4000: SCAN01>, chuteListStartPoint=<-1>, itemRevisionNumber=<10> ##[
170209 003126 0456 DE(N) ItemHandler.ItemLog event=<DESTINATION_REQUEST>, *******************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForData>, barcodes=<[ProxyWrapperBarcode(barcode=<T000042357>, type=<C0>, result=<OK>, ccType=<>)]>, ccReason=<SCANNER_DATA_ADDED>, PreviousccResult=<OK>, sortSchemeId=<-1>, sortSchemeName=<>, logicalDestination=<>, BatchCountItem=<true>, collectionId=<-1>, goodsId=<>, position=<sorter#0.scanner#4000: SCAN01>, dynamicDataCount=<0>, dynamicData=<{}>, carrierId=<202>, carrierCount=<1>, itemRevisionNumber=<10> ##[
170209 003126 0458 DE(N) ItemHandler.ItemLog event=<DESTINATION_REPLY>, *********************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, ccReason=<SCANNER_DATA_ADDED>, PendingccResult=<OK>, Pendingstrategy=<priority>, PendingchuteGroup=<[186, 188, 195, 201, 184]: [XRA502, XRA503, XRA605, XRA607, XRA501]>, PendingNotChutedestinationId=<-1>, PendingsortSchemeId=<-1>, PendingsortSchemeName=<>, PendinglogicalDestination=<XRA502>, PendinggoodsId=<>, PendingBatchCountItem=<true>, PendingcollectionId=<-1>, position=<sorter#0.scanner#4000: SCAN01>, dynamicDataCount=<0>, dynamicData=<{}>, itemRevisionNumber=<12> ##[
170209 003126 0458 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM>, *************************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, PendingchuteGroup=<[186, 188, 195, 201, 184]: [XRA502, XRA503, XRA605, XRA607, XRA501]>, Pendingstrategy=<priority>, CscdestinationId=<3000: Parked0>, CmcdestinationId=<3000: Parked0>, position=<sorter#0.scanner#4000: SCAN01>, itemRevisionNumber=<12> ##[
170209 003126 0681 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM_REPLY>, *******************, itemId=<12551674>, globalId=<12551674>, cmcIndex=<970>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, CscdestinationId=<186: XRA502>, chuteGroup=<[186, 188, 195, 201, 184]: [XRA502, XRA503, XRA605, XRA607, XRA501]>, CmcdestinationId=<186: XRA502>, position=<sorter#0.scanner#4000: SCAN01>, chuteListStartPoint=<186>, itemRevisionNumber=<14> ##[
170209 003126 0981 DE(N) ItemHandler.ItemLog event=<ITEM_INDUCTED>, *************************, itemId=<12551677>, globalId=<12551677>, cmcIndex=<973>, sorter=<0: MS01>, state=<CSC: WaitForData>, inductionId=<4: IU05>, inductionMode=<SCANNER>, inductStatus=<NORMAL_ITEM>, carrierId=<343>, carrierCount=<1>, CmcdestinationId=<4099: All Scanners>, position=<sorter#0: MS01>, itemRevisionNumber=<4> ##[
170209 003129 0845 DE(N) ItemHandler.ItemLog event=<ITEM_AT_INDUCTION>, *********************, itemId=<12551678>, globalId=<12551678>, cmcIndex=<974>, sorter=<0: MS01>, state=<CSC: ProjectIdle>, inductionId=<4: IU05>, position=<sorter#0.induction#4: IU05>, itemRevisionNumber=<0> ##[
170209 003129 0845 DE(N) ItemHandler.ItemLog event=<SET_ITEM_ID>, ***************************, itemId=<12551678>, globalId=<12551678>, cmcIndex=<974>, sorter=<0: MS01>, state=<CSC: ProjectIdle>, itemRevisionNumber=<0> ##[
170209 003130 0027 DE(N) ItemHandler.ItemLog event=<ITEM_PASSED_SPS>, ***********************, itemId=<12551665>, globalId=<12551665>, cmcIndex=<961>, sorter=<0: MS01>, state=<CSC: ProjectHeadingForChute>, carrierId=<363>, carrierCount=<1>, CmcdestinationId=<198: EXP507>, CscdestinationId=<198: EXP507>, itemRevisionNumber=<15> ##[
170209 003130 0350 DE(N) ItemHandler.ItemLog event=<DISCHARGE_ATTEMPTED>, *******************, itemId=<12551665>, globalId=<12551665>, cmcIndex=<961>, sorter=<0: MS01>, state=<CSC: ProjectHeadingForChute>, CscdestinationId=<198: EXP507>, chuteGroup=<[198]: EXP507>, CmcdestinationId=<198: EXP507>, position=<sorter#0: MS01>, itemRevisionNumber=<15> ##[
170209 003130 0352 DE(N) ItemHandler.ItemLog event=<RECONVERT>, *****************************, itemId=<12551665>, globalId=<12551665>, cmcIndex=<961>, sorter=<0: MS01>, state=<CSC: ProjectHeadingForChute>, CscdestinationId=<198: EXP507>, chuteGroup=<[198]: EXP507>, CmcdestinationId=<198: EXP507>, position=<sorter#0: MS01>, chuteListStartPoint=<198>, itemRevisionNumber=<16> ##[
170209 003130 0352 DE(N) ItemHandler.ItemLog event=<DESTINATION_REQUEST>, *******************, itemId=<12551665>, globalId=<12551665>, cmcIndex=<961>, sorter=<0: MS01>, state=<CSC: ProjectHeadingForChute>, barcodes=<[ProxyWrapperBarcode(barcode=<3709160626>, type=<A0>, result=<OK>, ccType=<>), ProxyWrapperBarcode(barcode=<2LIN400023+48000001>, type=<C0>, result=<OK>, ccType=<>)]>, ccReason=<SCANNER_DATA_ADDED>, PreviousccResult=<OK>, sortSchemeId=<-1>, sortSchemeName=<>, logicalDestination=<EXP507>, BatchCountItem=<true>, collectionId=<-1>, goodsId=<>, position=<sorter#0: MS01>, dynamicDataCount=<1>, dynamicData=<{VID=2017020905551665}>, carrierId=<363>, carrierCount=<1>, itemRevisionNumber=<16> ##[
170209 003130 0354 DE(N) ItemHandler.ItemLog event=<DESTINATION_REPLY>, *********************, itemId=<12551665>, globalId=<12551665>, cmcIndex=<961>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, ccReason=<SCANNER_DATA_ADDED>, PendingccResult=<OK>, Pendingstrategy=<notSpecified>, PendingchuteGroup=<[3000]: Parked0>, PendingNotChutedestinationId=<-1>, PendingsortSchemeId=<-1>, PendingsortSchemeName=<>, PendinglogicalDestination=<>, PendinggoodsId=<>, PendingBatchCountItem=<true>, PendingcollectionId=<-1>, position=<sorter#0: MS01>, dynamicDataCount=<1>, dynamicData=<{VID=2017020905551665}>, itemRevisionNumber=<18> ##[
170209 003130 0354 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM>, *************************, itemId=<12551665>, globalId=<12551665>, cmcIndex=<961>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, PendingchuteGroup=<[3000]: Parked0>, Pendingstrategy=<notSpecified>, CscdestinationId=<198: EXP507>, CmcdestinationId=<198: EXP507>, position=<sorter#0: MS01>, itemRevisionNumber=<18> ##[
170209 003130 0517 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM_REPLY>, *******************, itemId=<12551665>, globalId=<12551665>, cmcIndex=<961>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, CscdestinationId=<3000: Parked0>, chuteGroup=<[3000]: Parked0>, CmcdestinationId=<3000: Parked0>, position=<sorter#0: MS01>, chuteListStartPoint=<198>, itemRevisionNumber=<20> ##[
170209 003130 0520 DE(N) ItemHandler.ItemLog event=<RECONVERT>, *****************************, itemId=<12551665>, globalId=<12551665>, cmcIndex=<961>, sorter=<0: MS01>, state=<CSC: WaitForData>, CscdestinationId=<3000: Parked0>, chuteGroup=<[3000]: Parked0>, CmcdestinationId=<3000: Parked0>, position=<sorter#0: MS01>, chuteListStartPoint=<198>, itemRevisionNumber=<21> ##[
The issue I have is that I can't get the above command line to work because of the issues around single and double quotes when I run it in a windows batch file in DOS, I have other gawk commands working but they use " double quotes can anyone help
Thanks
Phil

Getting quotes and sometimes other special characters correctly through Windows commandline is frequently hard, especially with programs designed for Unix like gawk because there are several different methods of porting Unix-based or otherwise non-Windows C programs to the multiple subtly different implementations of C (or C++) on Windows.
A usually better approach for awk (and perl) in particular is to put the script in a file, something like this, which also allows you to use linebreaks to format it better:
myscript.awk:
{a = gensub(/([0-9]{6} [0-9]{6} [0-9]{4}).*itemId=, "\\2 \\1", "g", $0);
b = split(a, c, " ");
if (c[1] in result) result[c[1]] = gensub(/(.+),(.+)/, "\\1," c[2] " " c[3] " " c[4], "g", result[c[1]]);
else result[c[1]] = c[2] " " c[3] " " c[4] "," c[2] " " c[3] " " c[4] }
END { for (i in result) print i ": " result[i] }
then
gawk -f myscript.awk item.log
PS: your first gensub is clearly missing its closing / presumably after itemId= but even with that change it makes little sense because you have only one capture group but you specify a replacement string that uses two. Conversely your second gensub (the one in the if branch) has two capture groups but uses only one. Please check back with whoever 'helped' you.

Related

How to check if an attribute is present in an xml node using xmllint

I'm using bash and xmllint to check nodes in the following xml:
<?xml version="1.0" encoding="utf-8"?>
<output>
<document>
<sentence id="13">
<text>This is a test sentence.</text>
<entities>
<annotation id="3">
<grammar-form id="0" normal-form="THIS"/>
</annotation>
<annotation id="4">
<grammar-form id="0" normal-form="IS"/>
</annotation>
<annotation id="5">
<grammar-form id="0" normal-form="A"/>
</annotation>
<annotation id="6">
<grammar-form id="0" normal-form="TEST"/>
</annotation>
<annotation id="7">
<grammar-form id="0" normal-form="SENTENCE"/>
</annotation>
<annotation id="12">
<grammar-form id="0" normal-form="."/>
</annotation>
</entities>
</sentence>
</document>
</output>
How can I simply check that each grammar-form node has a normal-form attribute present? It doesn't matter what the attribute value is, I just need to check that it is present.
It's easier to select grammar-forms that don't have the attribute and see if you get any matches or not:
if xmllint --xpath '//grammar-form[not(#normal-form)]' input.xml 1>/dev/null 2>&1; then
echo "There are missing normal forms."
else
echo "There are no missing normal forms."
fi
In xpath mode, xmllint will print the matching paths, or if nothing matches, exit with a error code of 10 and print a message to that effect to standard error (the --noout option mentioned in the manpage to suppress output doesn't do anything in the version I'm testing with, unfortunately), hence the redirections.

Error: end-of-file after a modification of my Fortran code

I am using Fortran code to make it easier to extract the data I need from my many output files. First, I built a code to use with a specific file called 'output.sub' and it works fine to extract the various variables I needed. Now, I tried to use the code with another file 'output.rch' which has a similar structure to the previous one. Changed what needs to be changed to address the new output file, but now I get the end-of-file error. I am using Fixed-Form Fortran file on Visual Studios Professional 2017.
This is the old code:
PROGRAM WATER_BALANCE
IMPLICIT NONE
INTEGER I,J,K
INTEGER FLAGP(516),FLAGS(516),FLAGPET(516),FLAGET(516),
$ FLAGSW(516),FLAGPER(516),FLAGSUR(516),FLAGGW(516),FLAGWYLD(516)
REAL A,B,C,D,E,F,G,H,L
REAL PRECIP(516),SNOMELT(516),PET(516),ET(516),SW(516),PERC(516),
$SURQ(516),GW_Q(516),WYLD(516)
REAL PETB(14,516) !1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012
DO I=1,516
PRECIP(I)=0.0
SNOMELT(I)=0.0
PET(I)=0.0
ET(I)=0.0
SW(I)=0.0
PERC(I)=0.0
SURQ(I)=0.0
GW_Q(I)=0.0
WYLD(I)=0.0
END DO
OPEN(1,FILE='output.sub',STATUS='OLD')
DO I=1,9
READ(1,*)
END DO
DO I=1,365 !1999Äê
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(1,K)=PET(K)/365
PET(K)=0.0
END DO
DO I=366,731 !2000
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(2,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=732,1096 !2001
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(3,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=1097,1461 !2002
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(4,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=1462,1826 !2003
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(5,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=1827,2191 !2004
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(6,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=2192,2556 !2005
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(7,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=2557,2921 !2006
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(8,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=2922,3287 !2007
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(9,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=3288,3653 !2008
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(10,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=3654,4018 !2009
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(11,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=4019,4383 !2010
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(12,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=4384,4748 !2011
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(13,K)=PET(K)/366
PET(K)=0.0
END DO
DO I=4749,5114 !2012
DO J=1,516
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
PRECIP(J)=PRECIP(J)+A
SNOMELT(J)=SNOMELT(J)+B
PET(J)=PET(J)+C
ET(J)=ET(J)+D
SW(J)=SW(J)+E
PERC(J)=PERC(J)+F
SURQ(J)=SURQ(J)+G
GW_Q(J)=GW_Q(J)+H
WYLD(J)=WYLD(J)+L
END DO
END DO
DO K=1,516
PETB(14,K)=PET(K)/366
PET(K)=0.0
END DO
OPEN(2,FILE='OUT',STATUS='UNKNOWN')
DO K=1,516
WRITE(2,"(14(E10.3,5X))") PETB(1,K),PETB(2,K),PETB(3,K),PETB(4,K),
$ PETB(5,K),PETB(6,K),PETB(7,K),PETB(8,K),PETB(9,K),
$ PETB(10,K),PETB(11,K),PETB(12,K),PETB(13,K),PETB(14,K)
END DO
CLOSE(1)
CLOSE(2)
END
UPDATED: And this is the modified code to use with 'output.rch' file:
PROGRAM WATER_QUALITY
IMPLICIT NONE
INTEGER X,Y,Z
INTEGER FLAGFIN(516),FLAGFOUT(516),FLAGEVAP(516),FLAGTLOSS(516),
$ FLAGSIN(516),FLAGSOUT(516),FLAGSED(516),FLAGONIN(516),
$ FLAGONOUT(516), FLAGPIN(516),FLAGPOUT(516),FLAGNO3IN(516),
$ FLAGNO3OUT(516), FLAGNH4IN(516),FLAGNH4OUT(516),FLAGNO2IN(516),
$ FLAGNO2OUT(516)
REAL A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q
REAL FLOW_IN(516),FLOW_OUT(516),EVAP(516),TLOSS(516),SED_IN(516),
$SED_OUT(516),SEDCONC(516),ORGN_IN(516),ORGN_OUT(516),ORGP_IN(516),
$ORGP_OUT(516),NO3_IN(516),NO3_OUT(516),NH4_IN(516),NH4_OUT(516),
$NO2_IN(516),NO2_OUT(516)
REAL NO3_INB(15,516) !1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013
DO X=1,516
FLOW_IN(X)=0.0
FLOW_OUT(X)=0.0
EVAP(X)=0.0
TLOSS(X)=0.0
SED_IN(X)=0.0
SED_OUT(X)=0.0
SEDCONC(X)=0.0
ORGN_IN(X)=0.0
ORGN_OUT(X)=0.0
ORGP_IN(X)=0.0
ORGP_OUT(X)=0.0
NO3_IN(X)=0.0
NO3_OUT(X)=0.0
NH4_IN(X)=0.0
NH4_OUT(X)=0.0
NO2_IN(X)=0.0
NO2_OUT(X)=0.0
END DO
OPEN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T(Y)+I
ORGP_IN(Y)=ORGP_IN(Y)+J
ORGP_OUT(Y)=ORGP_OUT(Y)+K
NO3_IN(Y)=NO3_IN(Y)+L
NO3_OUT(Y)=NO3_OUT(Y)+M
NH4_IN(Y)=NH4_IN(Y)+N
NH4_OUT(Y)=NH4_OUT(Y)+O
NO2_IN(Y)=NO2_IN(Y)+P
NO2_OUT(Y)=NO2_OUT(Y)+Q
END DO
END DO
DO Z=1,516
NO3_INB(15,Z)=NO3_IN(Z)/366
NO3_IN(Z)=0.0
END DO
OPEN(11,FILE='OUT',STATUS='UNKNOWN')
DO Z=1,516
WRITE(11,"(15(E10.3,6X))") NO3_INB(1,Z),NO3_INB(2,Z),NO3_INB(3,Z),
$ NO3_INB(4,Z),NO3_INB(5,Z),NO3_INB(6,Z),NO3_INB(7,Z),
$ NO3_INB(8,Z),NO3_INB(9,Z),NO3_INB(10,Z),NO3_INB(11,Z),
$ NO3_INB(12,Z),NO3_INB(13,Z),NO3_INB(14,Z),NO3_INB(15,Z)
END DO
CLOSE(10)
CLOSE(11)
END
This is part of how the 'output.sub' looks like (the file that works):
1
SWAT Dec 23 2016 VER 2016/Rev 664 0/ 0/ 0 0: 0: 0
General Input/Output section (file.cio):
12/3/2018 12:00:00 AM ARCGIS-SWAT interface AV
SUB GIS MO DA YR AREAkm2 PRECIPmm SNOMELTmm PETmm ETmm SWmm PERCmm SURQmm GW_Qmm WYLDmm SYLDt/ha ORGNkg/ha ORGPkg/haNSURQkg/ha SOLPkg/ha SEDPkg/ha LAT Q(mm)LATNO3kg/hGWNO3kg/haCHOLAmic/LCBODU mg/L DOXQ mg/L TNO3kg/ha QTILEmm TVAPkg/ha
BIGSUB 1 0 1 1 1999 .11443E+03 0.200E+00 0.000E+00 0.000E+00 0.000E+00 0.201E+03 0.000E+00 0.506E-02 0.409E-01 0.844E-01 0.714E-05 0.281E-03 0.365E-04 0.246E-03 0.232E-05 0.424E-04 0.471E-02 0.368E-03 0.180E-05 .79489E-06 0.000E+00 0.123E-01 0.000E+00 0.000E+00 0.000E+00
BIGSUB 2 0 1 1 1999 .13345E+03 0.200E+00 0.000E+00 0.000E+00 0.000E+00 0.214E+03 0.000E+00 0.466E-02 0.418E-01 0.866E-01 0.543E-05 0.247E-03 0.322E-04 0.233E-03 0.226E-05 0.370E-04 0.588E-02 0.484E-03 0.208E-05 .55263E-06 0.000E+00 0.126E-01 0.000E+00 0.000E+00 0.000E+00
BIGSUB 3 0 1 1 1999 .64204E+02 0.000E+00 0.000E+00 0.341E+00 0.169E+00 0.440E+03 0.000E+00 0.627E-03 0.150E+00 0.275E+00 0.164E-07 0.159E-04 0.209E-05 0.178E-04 0.451E-06 0.233E-05 0.952E-03 0.793E-04 0.175E-04 .45972E-10 0.000E+00 0.401E-01 0.000E+00 0.000E+00 0.000E+00
BIGSUB 4 0 1 1 1999 .43200E+00 0.000E+00 0.000E+00 0.342E+00 0.163E+00 0.550E+03 0.000E+00 0.517E-06 0.197E+00 0.348E+00 0.237E-10 0.517E-09 0.517E-09 0.517E-09 0.517E-09 0.103E-08 0.000E+00 0.000E+00 0.872E-04 .16009E-21 0.000E+00 0.507E-01 0.000E+00 0.000E+00 0.000E+00
And here is how the 'output.rch' file looks like:
1
SWAT Dec 23 2016 VER 2016/Rev 664 0/ 0/ 0 0: 0: 0
General Input/Output section (file.cio):
12/3/2018 12:00:00 AM ARCGIS-SWAT interface AV
RCH GIS MO DA YR AREAkm2 FLOW_INcms FLOW_OUTcms EVAPcms TLOSScms SED_INtons SED_OUTtons SEDCONCmg/L ORGN_INkg ORGN_OUTkg ORGP_INkg ORGP_OUTkg NO3_INkg NO3_OUTkg NH4_INkg NH4_OUTkg NO2_INkg NO2_OUTkg MINP_INkg MINP_OUTkg CHLA_INkg CHLA_OUTkg CBOD_INkg CBOD_OUTkg DISOX_INkg DISOX_OUTkg SOLPST_INmgSOLPST_OUTmg SORPST_INmgSORPST_OUTmg REACTPSTmg VOLPSTmg SETTLPSTmgRESUSP_PSTmgDIFFUSEPSTmgREACBEDPSTmg BURYPSTmg BED_PSTmg BACTP_OUTctBACTLP_OUTct CMETAL#1kg CMETAL#2kg CMETAL#3kg TOT Nkg TOT Pkg NO3ConcMg/l WTMPdegc
REACH 1 0 1 1 1999 0.1144E+03 0.1118E+00 0.1139E+00 0.0000E+00 0.1118E+00 0.8167E-01 0.8167E-01 0.8301E+01 0.3215E+01 0.2903E+01 0.9024E+00 0.7628E+00 0.7042E+01 0.7173E+01 0.0000E+00 0.2906E+00 0.0000E+00 0.0000E+00 0.2660E-01 0.8129E-01 0.9096E-02 0.0000E+00 0.0000E+00 0.0000E+00 0.1408E+03 0.1425E+03 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.1037E+02 0.8441E+00 0.7291E+00 -0.2837E+01
REACH 2 0 1 1 1999 0.1335E+03 0.1338E+00 0.1366E+00 0.0000E+00 0.1338E+00 0.7249E-01 0.7249E-01 0.6140E+01 0.3292E+01 0.2978E+01 0.9225E+00 0.7812E+00 0.9594E+01 0.9795E+01 0.0000E+00 0.2949E+00 0.0000E+00 0.0000E+00 0.3013E-01 0.9229E-01 0.7375E-02 0.0000E+00 0.0000E+00 0.0000E+00 0.1686E+03 0.1710E+03 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.1307E+02 0.8735E+00 0.8297E+00 -0.2837E+01
REACH 3 0 1 1 1999 0.3121E+03 0.4549E+00 0.4618E+00 0.0000E+00 0.4549E+00 0.1543E+00 0.3399E+00 0.8519E+01 0.5983E+01 0.5373E+01 0.1572E+01 0.1322E+01 0.1770E+02 0.1797E+02 0.5855E+00 0.1071E+01 0.0000E+00 0.6687E-01 0.1765E+00 0.4064E+00 0.2952E-06 0.0000E+00 0.0000E+00 0.0000E+00 0.5710E+03 0.5779E+03 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.2448E+02 0.1729E+01 0.4505E+00 -0.2837E+01
REACH 4 0 1 1 1999 0.4225E+03 0.6049E+00 0.6164E+00 0.0000E+00 0.6049E+00 0.3417E+00 0.5355E+00 0.1005E+02 0.5860E+01 0.5890E+01 0.1472E+01 0.1470E+01 0.2393E+02 0.2439E+02 0.1134E+01 0.1205E+01 0.6687E-01 0.7998E-01 0.4412E+00 0.4751E+00 0.6916E-20 0.0000E+00 0.0000E+00 0.0000E+00 0.7570E+03 0.7712E+03 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.3156E+02 0.1945E+01 0.4579E+00 -0.2837E+01
UPDATED: And this is the error I get:
forrtl: severe (64): input conversion error, unit 10, file C:\Users\etern\OneDrive\Documents\Indiana University\PhD Research\PhD Dissertation Writing\WabashProject\VisualStudioProjects\OutPutRCH\OutPutRCH\output.rch
Image PC Routine Line Source
libifcoremdd.dll 54013BA5 Unknown Unknown Unknown
libifcoremdd.dll 54059BDA Unknown Unknown Unknown
OutPutRCH.exe 00BD1E6E _MAIN__ 51 RCH.for
OutPutRCH.exe 00BF00D3 Unknown Unknown Unknown
OutPutRCH.exe 00BF24DE Unknown Unknown Unknown
OutPutRCH.exe 00BF23C7 Unknown Unknown Unknown
OutPutRCH.exe 00BF226D Unknown Unknown Unknown
OutPutRCH.exe 00BF2548 Unknown Unknown Unknown
KERNEL32.DLL 766A8484 Unknown Unknown Unknown
ntdll.dll 77173AB8 Unknown Unknown Unknown
ntdll.dll 77173A88 Unknown Unknown Unknown
**UPDATED:**Line 51 is this:
READ(10,"(44X,17E10.3)")A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q
The old format of the line that worked is:
READ(1,"(41X,9E10.3)") A,B,C,D,E,F,G,H,L
Here are the changes made to the code:
1- Changed FLAGs to create new headings to match new output file.
2- Changed initial value of each flag under first Do function.
3- Changed Open function to open new output file.
4- Changed the letters used to identify variables since the new files use 17 variables, vs. 9 in the old one.
5- The Do function that represents each year of the output files was changed to match the 17 variables.
6- Changed the Read function of each year to match the new file. The data in the old file started at column number 41 of the text file, in the new one, it starts at 45. Also, data in old file are 9 characters wide, in the new one, it is 10.
7- Changed Write function to create columns with 6 characters wide vs 5 as in the old file.
The was an error in the use of Fortran Edit Descriptors. In the original code SUB the read command was assaigned as 41X,E10.3, since the data needed for the analyses started after 41 spaces, and the lenght of the field including the space before the next field value. In this one there was a single space between each field.
The new code RCH was correctly assaigned to start at 44X but was still marked to start reading data from E10.4 which is incorrect since the length of the field is actually 12; ten numbers and two spaces before the next field. The correct code is posted here for reference:
PROGRAM WATER_QUALITY
IMPLICIT NONE
INTEGER X,Y,Z
INTEGER FLAGFIN(516),FLAGFOUT(516),FLAGEVAP(516),FLAGTLOSS(516),
$ FLAGSIN(516),FLAGSOUT(516),FLAGSED(516),FLAGONIN(516),
$ FLAGONOUT(516), FLAGPIN(516),FLAGPOUT(516),FLAGNO3IN(516),
$ FLAGNO3OUT(516), FLAGNH4IN(516),FLAGNH4OUT(516),FLAGNO2IN(516),
$ FLAGNO2OUT(516)
REAL A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q
REAL FLOW_IN(516),FLOW_OUT(516),EVAP(516),TLOSS(516),SED_IN(516),
$SED_OUT(516),SEDCONC(516),ORGN_IN(516),ORGN_OUT(516),ORGP_IN(516),
$ORGP_OUT(516),NO3_IN(516),N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(Y)=NO2_OUT(Y)+Q
END DO
END DO
DO Z=1,516
NO3_INB(14,Z)=NO3_IN(Z)/366
NO3_IN(Z)=0.0
END DO
OPEN(11,FILE='OUT',STATUS='UNKNOWN')
DO Z=1,516
WRITE(11,"(14(E10.4,6X))") NO3_INB(1,Z),NO3_INB(2,Z),NO3_INB(3,Z),
$ NO3_INB(4,Z),NO3_INB(5,Z),NO3_INB(6,Z),NO3_INB(7,Z),
$ NO3_INB(8,Z),NO3_INB(9,Z),NO3_INB(10,Z),NO3_INB(11,Z),
$ NO3_INB(12,Z),NO3_INB(13,Z),NO3_INB(14,Z)
END DO
CLOSE(10)
CLOSE(11)
END

Hbase Cloudera java.lang.AbstractMethodError: org.apache.hadoop.hbase.ipc.RpcScheduler.getWriteQueueLength

I am using Cloudera CDH for my Hadoop Cluster. Suddenly, I noticed that I have the following errors in my HBase log files. These errors occur every time no matter what job I run. How do I fix the errors? P.S. So far they didn't cause any serious failover.
So these errors happen in the second cluster too.
log /jmx javax.management.RuntimeErrorException: getMBeanInfo threw Error
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBeanInfo(DefaultMBeanServerInterceptor.java:1387)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getMBeanInfo(JmxMBeanServer.java:920)
at org.apache.hadoop.hbase.util.JSONBean.write(JSONBean.java:125)
at org.apache.hadoop.hbase.util.JSONBean.access$000(JSONBean.java:53)
at org.apache.hadoop.hbase.util.JSONBean$1.write(JSONBean.java:96)
at org.apache.hadoop.hbase.http.jmx.JMXJsonServlet.doGet(JMXJsonServlet.java:202)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
at org.apache.hadoop.hbase.http.lib.StaticUserWebFilter$StaticUserFilter.doFilter(StaticUserWebFilter.java:113)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.apache.hadoop.hbase.http.ClickjackingPreventionFilter.doFilter(ClickjackingPreventionFilter.java:48)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.apache.hadoop.hbase.http.HttpServer$QuotingInputFilter.doFilter(HttpServer.java:1354)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.apache.hadoop.hbase.http.NoCacheFilter.doFilter(NoCacheFilter.java:49)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.apache.hadoop.hbase.http.NoCacheFilter.doFilter(NoCacheFilter.java:49)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:767)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.AbstractMethodError:
> org.apache.hadoop.hbase.ipc.RpcScheduler.getWriteQueueLength()I
> at org.apache.hadoop.hbase.ipc.MetricsHBaseServerWrapperImpl.getWriteQueueLength(MetricsHBaseServerWrapperImpl.java:87)
> at org.apache.hadoop.hbase.ipc.MetricsHBaseServerSourceImpl.getMetrics(MetricsHBaseServerSourceImpl.java:228)
> at org.apache.hadoop.metrics2.impl.MetricsSourceAdapter.getMetrics(MetricsSourceAdapter.java:199)
> at org.apache.hadoop.metrics2.impl.MetricsSourceAdapter.updateJmxCache(MetricsSourceAdapter.java:182)
> at org.apache.hadoop.metrics2.impl.MetricsSourceAdapter.getMBeanInfo(MetricsSourceAdapter.java:155)
> at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBeanInfo(DefaultMBeanServerInterceptor.java:1378)
> ... 34 more
> View Log File
> ws-hadoop-data-4 ERROR December 19, 2017 2:59 AM log
> Nested in javax.management.RuntimeErrorException: getMBeanInfo threw Error:
> java.lang.AbstractMethodError: org.apache.hadoop.hbase.ipc.RpcScheduler.getWriteQueueLength()I
> at org.apache.hadoop.hbase.ipc.MetricsHBaseServerWrapperImpl.getWriteQueueLength(MetricsHBaseServerWrapperImpl.java:87)
> at org.apache.hadoop.hbase.ipc.MetricsHBaseServerSourceImpl.getMetrics(MetricsHBaseServerSourceImpl.java:228)
> at org.apache.hadoop.metrics2.impl.MetricsSourceAdapter.getMetrics(MetricsSourceAdapter.java:199)
> at org.apache.hadoop.metrics2.impl.MetricsSourceAdapter.updateJmxCache(MetricsSourceAdapter.java:182)
> at org.apache.hadoop.metrics2.impl.MetricsSourceAdapter.getMBeanInfo(MetricsSourceAdapter.java:155)
> at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBeanInfo(DefaultMBeanServerInterceptor.java:1378)
> at com.sun.jmx.mbeanserver.JmxMBeanServer.getMBeanInfo(JmxMBeanServer.java:920)
> at org.apache.hadoop.hbase.util.JSONBean.write(JSONBean.java:125)
> at org.apache.hadoop.hbase.util.JSONBean.access$000(JSONBean.java:53)
> at org.apache.hadoop.hbase.util.JSONBean$1.write(JSONBean.java:96)
> at org.apache.hadoop.hbase.http.jmx.JMXJsonServlet.doGet(JMXJsonServlet.java:202)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
> at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
> at org.apache.hadoop.hbase.http.lib.StaticUserWebFilter$StaticUserFilter.doFilter(StaticUserWebFilter.java:113)
> at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
> at org.apache.hadoop.hbase.http.ClickjackingPreventionFilter.doFilter(ClickjackingPreventionFilter.java:48)
> at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
> at org.apache.hadoop.hbase.http.HttpServer$QuotingInputFilter.doFilter(HttpServer.java:1354)
> at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
> at org.apache.hadoop.hbase.http.NoCacheFilter.doFilter(NoCacheFilter.java:49)
> at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
> at org.apache.hadoop.hbase.http.NoCacheFilter.doFilter(NoCacheFilter.java:49)
> at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
> at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
> at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
> at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
> at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:767)
> at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
> at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
> at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
> at org.mortbay.jetty.Server.handle(Server.java:326)
> at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
> at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
> at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
> at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
> at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
> at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

Check vim version and python support from a bash script

I have a bash script that is dependent on vim being at least version 7.4 and is installed with python. I need to check if the above condition matches, if not exit and ask user to update their vim.
So far all I can think of is something like below
has_vim = command -v vim >/dev/null
if ! $has_vim; then
echo "must have vim installed."
exit 1
fi
// Here I want do as the following pseudo code
vim_info = $(vim --version | grep python)
// suggest me if there is another way
vim_version = // find version info from $vim_info
has_python_support = // find python support from $vim_info
if ! $vim_version >= 7.4 && ! has_python_support; then
echo "vim version must be at least 7.4 and must be installed with python support"
fi
// everything is ok. carry on
At the moment all I can think of is checking $vim_info for expected vim version and python support.
To boil down the question into meaningful sentence:
How do I check if vim version is greater or equal to 7.4 and has python support from bash script?
When I ask my vim for vim --version, it spits out something like this:
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 16 2015 08:44:57)
Included patches: 1-872
Compiled by <alexpux#gmail.com>
Huge version without GUI. Features included (+) or not (-):
+acl +farsi +mouse_netterm +syntax
+arabic +file_in_path +mouse_sgr +tag_binary
+autocmd +find_in_path -mouse_sysmouse +tag_old_static
-balloon_eval +float +mouse_urxvt -tag_any_white
-browse +folding +mouse_xterm -tcl
++builtin_terms -footer +multi_byte +terminfo
+byte_offset +fork() +multi_lang +termresponse
+cindent +gettext -mzscheme +textobjects
-clientserver -hangul_input +netbeans_intg +title
+clipboard +iconv +path_extra -toolbar
+cmdline_compl +insert_expand +perl/dyn +user_commands
+cmdline_hist +jumplist +persistent_undo +vertsplit
+cmdline_info +keymap +postscript +virtualedit
+comments +langmap +printer +visual
+conceal +libcall +profile +visualextra
+cryptv +linebreak +python/dyn +viminfo
+cscope +lispindent +python3/dyn +vreplace
+cursorbind +listcmds +quickfix +wildignore
+cursorshape +localmap +reltime +wildmenu
+dialog_con -lua +rightleft +windows
+diff +menu +ruby/dyn +writebackup
+digraphs +mksession +scrollbind -X11
-dnd +modify_fname +signs -xfontset
-ebcdic +mouse +smartindent -xim
+emacs_tags -mouseshape -sniff -xsmp
+eval +mouse_dec +startuptime -xterm_clipboard
+ex_extra -mouse_gpm +statusline -xterm_save
+extra_search -mouse_jsbterm -sun_workshop -xpm
So, parsing the output would be a good bet here.
Find the version number and store it in VIMVERSION:
VIMVERSION=$(vim --version | head -1 | cut -d ' ' -f 5)
From here, check In bash shell script how do I convert a string to an number for how to compare the string result against your minimum needed 7.4.
Check for Python support (HAS_PYTHON will be 0 if Python is not available):
HAS_PYTHON=$(vim --version | grep -c '+python')
Check explicitly for Python 3 (again, HAS_PYTHON3 will be 0 if Python 3 is not available):
HAS_PYTHON3=$(vim --version | grep -c '+python3')
This might be a bit rough but I think you get the idea.
#!/bin/bash
has_vim=$(command -v vim >/dev/null)
if ! $has_vim; then
echo "must have vim installed."
exit 1
fi
# Checking the python support based on the line output received
has_python_support=$(vim --version | grep -c python)
# Matching the decimal pattern from the first line
vim_version=$(vim --version | head -1 | grep -o '[0-9]\.[0-9]')
if [ ! $(echo "$vim_version >= 7.4" | bc -l) ] && [ ! $has_python_support ]; then
echo "vim version must be at least 7.4 and must be installed with python support"
else
echo "vim version is > 7.4"
fi
Should solve your problem
If you have a running Vim instance already, or if you can create one, you can always just ask Vim itself:
$ vim --servername SOME_NAME --remote-expr "has('python')"
1
$ vim --servername SOME_NAME --remote-expr "v:version"
704
But if Vim isn't already running it's probably more straightforward to parse the --version output as suggested in other answers.

Correct BCP syntax

I am a first time BCP user. I have an XML file that I need to import into a new table in SQL Server. This is using SQL Server 2008 and BCP version 10.50.16. I read through the documentation but I get 370,000 errors! (This is a very large file). When I open the error log, I just see a bunch of question marks.
About this XML file: it does use a new line to delineate rows, however, it uses the space character to separate fields. So I'm not sure if that is what causes it to fail. The failure message is:
BCP copy in failedI wish it were more descriptive. Is there a way to get a more detailed error message?
Otherwise, here is my command:
d:\SQL Tables\data>bcp Development.dbo.wbl_zSkywardEnrollment2 in zSkywardEnroll
ment.xml -fSE_format.fmt -m50 -eseErrorLog -b100 -t0x20 -T -F107
All of these files are in this same directory. I know it says to specify full file path, but since they're all in this same directory and also I saw another example where they didn't specify directories I thought this would suffice.
I have tried this without the format file also, doing it interactively but get same errors.
This is my format file:
10.0
32
1 SQLINT 0 4 " " 1 SCHOOL_YEAR ""
2 SQLNCHAR 2 20 " " 2 ENTITY_ID SQL_Latin1_General_CP1_CI_AS
3 SQLINT 0 4 " " 3 TERM_NBR ""
4 SQLINT 1 4 " " 4 SCHD_HST_GRAD_YEAR ""
5 SQLNCHAR 2 60 " " 5 OTHER_ID SQL_Latin1_General_CP1_CI_AS
6 SQLNUMERIC 1 19 " " 6 GRAD_YR ""
7 SQLNCHAR 2 120 " " 7 LAST_NAME SQL_Latin1_General_CP1_CI_AS
8 SQLNCHAR 2 60 " " 8 FIRST_NAME SQL_Latin1_General_CP1_CI_AS
9 SQLNCHAR 2 60 " " 9 MIDDLE_NAME SQL_Latin1_General_CP1_CI_AS
10 SQLDATETIME 1 8 " " 10 BIRTHDATE ""
11 SQLNCHAR 2 4 " " 11 GENDER SQL_Latin1_General_CP1_CI_AS
12 SQLNCHAR 2 20 " " 12 RACE_CODE SQL_Latin1_General_CP1_CI_AS
13 SQLNCHAR 2 40 " " 13 DISTRICT_CODE SQL_Latin1_General_CP1_CI_AS
14 SQLBIT 1 1 " " 14 X_SPECIAL_EDUCATION ""
15 SQLBIT 1 1 " " 15 X_GIFTED_TALENTED ""
16 SQLBIT 1 1 " " 16 X_SECTION_504 ""
17 SQLBIT 1 1 " " 17 X_MIGRANT ""
18 SQLBIT 1 1 " " 18 X_IEP ""
19 SQLBIT 1 1 " " 19 X_IEP_ACCOM ""
20 SQLBIT 1 1 " " 20 X_ESL ""
21 SQLNCHAR 2 4 " " 21 STUDENT_STATUS SQL_Latin1_General_CP1_CI_AS
22 SQLINT 0 4 " " 22 STUDENT_ID ""
23 SQLINT 1 4 " " 23 ENG_PROF ""
24 SQLNCHAR 2 60 " " 24 ALPHAKEY SQL_Latin1_General_CP1_CI_AS
25 SQLNCHAR 2 20 " " 25 SCHOOL_ID SQL_Latin1_General_CP1_CI_AS
26 SQLNUMERIC 1 19 " " 26 MN_EDE_NBR ""
27 SQLNCHAR 2 20 " " 27 LANGUAGE_CODE SQL_Latin1_General_CP1_CI_AS
28 SQLINT 1 4 " " 28 ADVISOR ""
29 SQLBIT 1 1 " " 29 MN_LIMITED_ENGLISH ""
30 SQLNCHAR 2 20 " " 30 TYPE_STUDENT_ID SQL_Latin1_General_CP1_CI_AS
31 SQLNCHAR 2 20 " " 31 CY_TEAM_SCHD_ID SQL_Latin1_General_CP1_CI_AS
32 SQLNCHAR 2 20 " " 32 HOMEROOM_NUMBER SQL_Latin1_General_CP1_CI_AS
This is my SQL table:
CREATE TABLE [dbo].[wbl_zSkywardEnrollment2](
[SCHOOL_YEAR] [int] NOT NULL,
[ENTITY_ID] [nvarchar](10) NOT NULL,
[TERM_NBR] [int] NOT NULL,
[SCHD_HST_GRAD_YEAR] [int] NULL,
[OTHER_ID] [nvarchar](30) NULL,
[GRAD_YR] numeric(19,0) NULL,
[LAST_NAME] [nvarchar](60) NOT NULL,
[FIRST_NAME] [nvarchar](30) NULL,
[MIDDLE_NAME] [nvarchar](30) NULL,
[BIRTHDATE] datetime NULL,
[GENDER] [nvarchar](2) NULL,
[RACE_CODE] [nvarchar](10) NULL,
[DISTRICT_CODE] [nvarchar](20) NULL,
[X_SPECIAL_EDUCATION] bit NULL,
[X_GIFTED_TALENTED] bit NULL,
[X_SECTION_504] bit NULL,
[X_MIGRANT] bit NULL,
[X_IEP] bit NULL,
[X_IEP_ACCOM] bit NULL,
[X_ESL] bit NULL,
[STUDENT_STATUS] [nvarchar](2) NULL,
[STUDENT_ID] [int] NOT NULL,
[ENG_PROF] [int] NULL,
[ALPHAKEY] [nvarchar](30) NOT NULL,
[SCHOOL_ID] [nvarchar](10) NULL,
[MN_EDE_NBR] [numeric](19, 0) NULL,
[LANGUAGE_CODE] [nvarchar](10) NULL,
[ADVISOR] [int] NULL,
[MN_LIMITED_ENGLISH] bit NULL,
[TYPE_STUDENT_ID] [nvarchar](10) NULL,
[CY_TEAM_SCHD_ID] [nvarchar](10) NULL,
[HOMEROOM_NUMBER] [nvarchar](10) NOT NULL
) ON [PRIMARY]
And I have tried this starting with row 1. I am curious which line should BCP start on? Line 1 of this XML starts with Schema and ElementType info. But on line 107 is where rs:data section starts.
The first part of this XML file:
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly'>
<s:AttributeType name='c0' rs:name='SCHOOL_YEAR' rs:number='1'>
<s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true' rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='c1' rs:name='ENTITY_ID' rs:number='2'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='10' rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='c2' rs:name='TERM_NBR' rs:number='3'>
<s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true' rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='c3' rs:name='SCHD_HST_GRAD_YEAR' rs:number='4' rs:nullable='true'>
<s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c4' rs:name='OTHER_ID' rs:number='5' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='24'/>
</s:AttributeType>
<s:AttributeType name='c5' rs:name='GRAD_YR' rs:number='6' rs:nullable='true'>
<s:datatype dt:type='number' rs:dbtype='numeric' dt:maxLength='19' rs:scale='0' rs:precision='15' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c6' rs:name='LAST_NAME' rs:number='7'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='60' rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='c7' rs:name='FIRST_NAME' rs:number='8' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='30'/>
</s:AttributeType>
<s:AttributeType name='c8' rs:name='MIDDLE_NAME' rs:number='9' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='30'/>
</s:AttributeType>
<s:AttributeType name='BIRTHDATE' rs:name='BIRTHDATE' rs:number='10' rs:nullable='true' rs:write='true'>
<s:datatype dt:type='date' dt:maxLength='6' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='GENDER' rs:name='GENDER' rs:number='11' rs:nullable='true' rs:write='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='2'/>
</s:AttributeType>
<s:AttributeType name='c11' rs:name='RACE_CODE' rs:number='12' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='6'/>
</s:AttributeType>
<s:AttributeType name='c12' rs:name='DISTRICT_CODE' rs:number='13' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='14'/>
</s:AttributeType>
<s:AttributeType name='c13' rs:name='X_SPECIAL_EDUCATION' rs:number='14' rs:nullable='true'>
<s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c14' rs:name='X_GIFTED_TALENTED' rs:number='15' rs:nullable='true'>
<s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c15' rs:name='X_SECTION_504' rs:number='16' rs:nullable='true'>
<s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c16' rs:name='X_MIGRANT' rs:number='17' rs:nullable='true'>
<s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c17' rs:name='X_IEP' rs:number='18' rs:nullable='true'>
<s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c18' rs:name='X_IEP_ACCOM' rs:number='19' rs:nullable='true'>
<s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c19' rs:name='X_ESL' rs:number='20' rs:nullable='true'>
<s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c20' rs:name='STUDENT_STATUS' rs:number='21' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='2'/>
</s:AttributeType>
<s:AttributeType name='c21' rs:name='STUDENT_ID' rs:number='22'>
<s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true' rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='c22' rs:name='ENGL_PROF' rs:number='23' rs:nullable='true'>
<s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='ALPHAKEY' rs:name='ALPHAKEY' rs:number='24' rs:write='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='22' rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='c24' rs:name='SCHOOL_ID' rs:number='25'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='10' rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='c25' rs:name='MN_EDE_NBR' rs:number='26' rs:nullable='true'>
<s:datatype dt:type='number' rs:dbtype='numeric' dt:maxLength='19' rs:scale='0' rs:precision='15' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c26' rs:name='LANGUAGE_CODE' rs:number='27' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='6'/>
</s:AttributeType>
<s:AttributeType name='c27' rs:name='ADVISOR' rs:number='28' rs:nullable='true' rs:write='true'>
<s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c28' rs:name='MN_LIMITED_ENGLISH' rs:number='29' rs:nullable='true'>
<s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c29' rs:name='TYPE_STUDENT_ID' rs:number='30' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='6'/>
</s:AttributeType>
<s:AttributeType name='c30' rs:name='CY_TEAM_SCHD_ID' rs:number='31' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='6'/>
</s:AttributeType>
<s:AttributeType name='c31' rs:name='HOMEROOM_NUMBER' rs:number='32'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='10' rs:maybenull='false'/>
</s:AttributeType>
<s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01'
GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False'
c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False'
c29='R' c30='' c31=''/>
<z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01'
GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False'
c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False'
c29='R' c30='' c31=''/>
<z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01'
GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False'
c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False'
c29='R' c30='' c31=''/>
<z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01'
GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False'
c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False'
c29='R' c30='' c31=''/>
<z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01'
GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False'
c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False'
c29='R' c30='' c31=''/>
<z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01'
GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False'
c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False'
c29='R' c30='' c31=''/>
You can't use bcp for this. The best that bcp can give you is an import from a file with comma/tab/etc. separated values. All references that you see to xml in the bcp documentation refer to the format file, not to the actual data to import.
There are actually two ways of doing this. The easiest is to use SQL Server Integration Services for this. This can help you further.
You could also do this by reading the xml file into SQL server. Then use sp_xml_preparedocument to parse the file. Finally, use OPENXML in combination with INSERT to import the data.

Resources