Skip lines at beginning of fixedlength file

958 views
Skip to first unread message

David Ryan

unread,
Apr 22, 2013, 7:50:56 PM4/22/13
to bea...@googlegroups.com
I have a file that looks like this:

InputFile.txt:
Some header text here. Like this.
[blank line]
Some more text here.
x, y, z, a, b, c
   0.000    0.000  -43.690   18.390  -43.763  142.391
  50.000    0.000  -23.358   50.378  -33.695  934.381
 100.000    0.000  -23.527   62.351  -10.327  324.386
 200.000    0.000  -35.996   34.311  -82.759  448.405
1000.000    0.000  -43.126   66.256  -13.590  850.640
   0.000   10.000  -67.436   28.189  -87.322  162.189
   1.000  100.000  -23.508   60.108  -13.853  184.553
   2.000 1000.000  -97.980   72.015  -58.683  946.631
   3.000    1.000  -12.453   33.910  -20.212  158.724
   4.000    0.000  -58.228   75.794  -13.441  800.831
   5.000    0.000  -89.704   77.667  -53.968  452.951
   6.000    0.000  -29.381   99.530  -23.394  725.084

I want to ignore the first 4 lines, and just parse the fixedlength data. How do I do that, given this as a starting point?
<stream name="abcdef" format="fixedlength">  
<record name="data" class="DataPointABCDEF">        
<field name="a" length="8" justify="right" type="java.lang.Double" />
<field name="b" length="9" justify="right" type="java.lang.Double" />
<field name="c" length="9" justify="right" type="java.lang.Double" />
<field name="d" length="9" justify="right" type="java.lang.Double" />
<field name="e" length="9" justify="right" type="java.lang.Double" />
<field name="f" length="9" justify="right" type="java.lang.Double" />
</record>       
</stream>   
</beanio>

Perhaps it's better to treat the whole file as delimited with the delimiters "," and " " (comma and space) and then I can use another record with "occurs=4" to ignore the first lines. I could also parse the column names that way (since comma is a delimiter).
But it seems like I should be able to do this using fixedlength format.

Thanks,
David

Kevin

unread,
Apr 22, 2013, 9:38:53 PM4/22/13
to bea...@googlegroups.com
Hi David,

Any records that are not bound to a class are effectively ignored.  So you just need to add another record that precedes your "data" record, and do not define any fields for it, like this:

    <record name="ignored" order="1" occurs="4" />

Ant it would probably be best to mark your data record with order="2" to ensure proper record ordering...

Thanks,
Kevin

David Ryan

unread,
Apr 23, 2013, 1:04:46 PM4/23/13
to bea...@googlegroups.com
That worked and was a lot easier than I thought.
Thanks.
Reply all
Reply to author
Forward
0 new messages