Using a scanner to parse a text file

Hi,
I'm running into some difficulties using a pattern for my scanner (java.util.Scanner). I need to scan a text file which consists of records. Each record has a keyword and a value (like property files):
Example:
FACILITY=TEST
LOT=1234567
DEVICE=abcdefgNormally, every record will be ended by a carriage return and line feed. So what I did was using a scanner with cr/lf as delimiter. That worked fine for most records but there are some records which span several lines (with cr/lf at the end of each line), e.g.:
MAP_XY.01.01=" Y-7 24/10 Y-6 24 22/17 15/7 Y-5 29/7 5 Y-4 32/22 20
19/15 13/4 Y-3 34/24 22/13 11/2 Y-2 36/30 28/24 22
21/12 10/4 2/0 Y-1 38/0 Y0 40/35 33/22 20/15 13/0 Y1 41
40/32 30/8 6/-1 Y2 42/26 24/-2 Y3 42/-5 Y4 47/11 9
8/3 1/-6 Y5 48/47 45/39 37/18 16/-7 Y6 49/8 6/-8 Y7 49
47/8 6/4 2/-8 Y8 50/9 7/3 1/-9 Y9 51/11 9/-10 Y10 51
50/33 31/-10 Y11 52/40 38/35 33/23 21/16 14/-11 Y12 52
51/34 32/15 13/4 2/-11 Y13 53/40 38/35 33/-12 Y14 53
52/35 33/27 25/18 16/13 11/9 7 5 2/0 -4/-12 Y15 53
52/-12 Y16 53/22 20/-5 -7/-13 Y17 54/47 45/-7 -9/-13 Y18 54
53/22 20 18/2 0/-13 Y19 55/16 14/13 11/-2 -4/-13 Y20 55
53/41 39/35 33/-14 Y21 55/52 50/48 46/16 14/10 8/-2 -4
-6/-14 Y22 54/33 31/7 5/4 2/0 -2/-9 -11/-13 Y23 55
54/53 51/26 24/-2 -4/-13 Y24 55/15 13/-14 Y25 55 53
52/-7 -9/-10 -12/-14 Y26 54/44 42/14 12/10 8/-4 -6
-7/-10 -12/-13 Y27 55/52 50/23 20/16 14/-13 Y28 54
53/12 10/-1 -3/-13 Y29 55/44 42/-13 Y30 55/15 13/10 8
7/-13 Y31 55/17 15/-13 Y32 54/44 42/-1 -3/-13 Y33 54
53/41 39/30 28/-13 Y34 54 52/37 35/19 17/12 9/8 5/3 1
0/-4 -6 -9/-11 Y35 54/-13 Y36 54/35 33/31 29/13 11
10/2 0/-2 -4/-13 Y37 54/-13 Y38 53/11 9/0 -2/-9 -11
-12 Y39 53/35 33/31 29/-12 Y40 53/22 20/15 13/-12 Y41 52
50/15 13/10 8/-11 Y42 52/11 9/5 3/-6 -8/-11 Y43 51
50/41 39/10 8/0 -2/-10 Y44 51/28 26 24/15 13/12 10
9/-10 Y45 50/43 41/32 30/4 2/-9 Y46 49/31 29/13 11
10/-8 Y47 49/47 45/30 28/24 22/-8 Y48 48/42 40 38/12 10
9/-7 Y49 47/42 40/38 36/-6 Y50 44/33 31/30 28/6 4/-5 Y51 44
43/28 26/17 15/13 11/-2 Y52 44/32 30/-2 Y53 43/32 30
29/13 11/-2 Y54 42/27 25/24 22/16 9 7/-1 Y55 41/21 19
18/0 Y56 39/15 13/6 4 2 Y57 38/20 18/3 Y58 36/5 Y59 34
33 31/30 28/7 Y60 31/28 26/10 Y61 27/14"
BIN_COUNT.01.09=12345Using the following delimiter does not work
fileScanner.useDelimiter("\\s*=\\s*");because the result would be something like:
keyword: FACILITY     value: TEST
LOTkeyword: 1234567
DEVICE     value: abcdefgWhat I need is a pattern which also handles carriage return/line feed until a new keyword (like LOT for example) occurs.
The correct result should be:
keyword: FACILITY     value: TEST
keyword: LOT            value: 1234567
keyword: DEVICE     value: abcdefg
keyword: MAP_XY.01.01 value: " Y-7 24/10 Y-6 24 22/17 15/7 Y-5 29/7 5 Y-4 32/22 20...
{code}
I hope, I did explain clearly enough...
Any help would be appreciated.
Thanks and best regards
- Stephan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Any help would be appreciated.You have grouping and data in the groupings and you are attempting to parse it all at one go.
Won't work. (Might in a perfect world but not in this one.)
You need a parsers that do the following
1. Parser text file (stream) into records.
2. Parse records into data.
You can put both into one class or not.
Your record parser is going to be based roughly on the following scheme.
1. Find keyword,
2. Look up format defined for keyword
3. Attempt to read format found.
4. Error if format not found.
5. Else return the record found.
I say roughly because as noted above you need to know what the actual output looks like. It is possible to determine this if you have enough examples but it is a lot easier if you actually get the specification that tells you what it looks like.
I suspect, but don't know that the "format" in the above will consist of the following.
<word><text>
or
<word><text>
<space><text>
<space><text>
You could just create one format for the all but you will likely have record types that don't fit that and the earlier you detect errors the better.

Similar Messages

  • Parsing a text file using regular expression

    hi all,
    i have a text file which is delimited by a pipe symbol.
    eg.|4| |2| |1| |abcde| 345 |2000|...................
    can anyone help me writing the regular expression for the above case.
    Thanks

    Would splitting the string into tokens help you?
    String s = "|4| |2| |1| |abcde| 345 |2000|";
    String[] token = s.split("\\|");
    int len = token.length;
    for (int i=0; i<len; i++) {
         String t = token.trim();
         if (!t.equals("")) {
              System.out.println(t);

  • VBScript for parsing multiple text files

    Hi,
    I have around 175 text files that contain inventory information that I am trying to parse into an Excel file. We are upgrading our Office platform from 2003 to 2010 and my boss wants to know which machines will have trouble supporting it. I found a script
    that will parse a single text file based upon ":" as the delimiter and I'm having trouble figuring out how to change it to open an entire folder of text files and write all of the data to a single Excel spreadsheet. Here is an example of the text
    file I'll be parsing. I'm interested in the "Memory and Processor Information" and "Disk Drive Information" sections mainly.
    ABEHRENS-XP Computer Inventory
    OS Information
    OS Details
    Caption: Microsoft Windows XP Professional
    Description:
    InstallDate: 20070404123855.000000-240
    Name: Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1
    Organization: Your Mom
    OSProductSuite:
    RegisteredUser: Bob
    SerialNumber: 55274-640-3763826-23029
    ServicePackMajorVersion: 3
    ServicePackMinorVersion: 0
    Version: 5.1.2600
    WindowsDirectory: C:\WINDOWS
    Memory and Processor Information
    504MB Total memory HOW CAN I PULL THIS WITHOUT ":" ALSO
    Computer Model: HP d330 uT(DG291A)
    Processor:               Intel(R) Pentium(R) 4 CPU 2.66GHz
    Disk Drive Information
    27712MB Free Disk Space ANY WAY TO PULL THIS WITHOUT ":"
    38162MB Total Disk Space
    Installed Software
    Here is the start of the script I have so far. . .
    Const ForReading = 1
    Set objDict = CreateObject("Scripting.Dictionary")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile("C:\Test\test.txt" ,ForReading)
    WANT THIS TO BE C:\Test
    Do Until objTextFile.AtEndOfStream
    strLine = objTextFile.ReadLine
    If Instr(strLine,":") Then
    arrSplit = Split(strLine,":") IS ":" THE BEST DELIMITER TO USE?
    strField = arrSplit(0)
    strValue = arrSplit(1)
    If Not objDict.Exists(strField) Then
    objDict.Add strField,strValue
    Else
    objDict.Item(strField) = objDict.Item(strField) & "||" & strValue
    End If
    End If
    Loop
    objTextFile.Close
    Set objExcel = CreateObject("Excel.Application")
    objExcel.Visible = True
    objExcel.Workbooks.Add
    intColumn = 1
    For Each strItem In objDict.Keys
    objExcel.Cells(1,intColumn) = strItem
    intColumn = intColumn + 1
    Next
    intColumn = 1
    For Each strItem In objDict.Items
    arrValues = Split(strItem,"||")
    intRow = 1
    For Each strValue In arrValues
    intRow = intRow + 1
    objExcel.Cells(intRow,intColumn) = strValue
    Next
    intColumn = intColumn + 1
    Next
    Thank you for any help.

    You are The Bomb.com! I had to play around with it to pull some additional data (model and processor) and then write a quick macro to remove the unwanted text and finally I wanted the data to write in columns instead of rows so this is what I ended up with:
    Option Explicit
    Dim objFSO, objFolder, strFolder, objFile
    Dim objReadFile, strLine, objExcel, objSheet
    Dim intCol, strExcelPath
    Const ForReading = 1
    strFolder = "c:\Test"
    strExcelPath = "c:\Test\Inventory.xlsx"
    Set objExcel = CreateObject("Excel.Application")
    objExcel.Workbooks.Add
    Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
    intCol = 0
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(strFolder)
    For Each objFile In objFolder.Files
      intCol = intCol + 1
      Set objReadFile = objFSO.OpenTextFile(objFile.Path, ForReading)
      Do Until objReadFile.AtEndOfStream
        strLine = objReadFile.ReadLine
        If (InStr(strLine, "Computer Inventory") > 0) Then
          objSheet.Cells(intCol, 1).Value = Left(strLine, InStr(strLine, "Computer Inventory") - 2)
        End If
        If (InStr(strLine, "Total memory") > 0) Then
          objSheet.Cells(intCol, 2).Value = Left(strLine, InStr(strLine, "Total memory") - 2)
        End If
        If (InStr(strLine, "Computer Model:") > 0) Then
          objSheet.Cells(intCol, 3).Value = (strLine)
        End If
        If (InStr(strLine, "Processor:") > 0) Then
          objSheet.Cells(intCol, 4).Value = (strLine)
        End If
        If (InStr(strLine, "Total Disk Space") > 0) Then
          objSheet.Cells(intCol, 5).Value = Left(strLine, InStr(strLine, "Total Disk Space") - 2)
        End If
        If (InStr(strLine, "Free Disk Space") > 0) Then
          objSheet.Cells(intCol, 6).Value = Left(strLine, InStr(strLine, "Free Disk Space") - 2)
        End If
      Loop
    Next
    objExcel.ActiveWorkbook.SaveAs strExcelPath
    objExcel.ActiveWorkbook.Close
    objExcel.Quit
    Thanks again!
    Hi ,
    I am have very basic knowledge about VB scripting, but this code could be the perfect solution i am looking for. could you guide me exactly how to run and test the same , i would be really thankful for your kind and generous support on this.
    Thanks ,
    Veer

  • Parsing a Text file with nulls in records

    Hello All,
    I am relatively new to Java programming and I have been given a task that requires me to parse a CSV text file. I have to group the records based on a particular column and then do some math (add columns that have same keys). My problem is that the input file can have nulls and non numeric chars. I am confused how I can proceed in this situation, since I have to add these records, when I do a parseDouble it might fail. OK. I can get around it by assigning a zero in case there is a NumberFormatException but the result of my task is to render an output text file that from the input file. Here comes the catch, the requirement has it, that if the input file had a null or a non numeric char then while rendering the output, I have to populate a code as a place holder for that location where a null or non numeric char was found. I'd like to know if there is any trivial way of getting around this problem without using a Map to remember the location where the null was found. Any help is greatly appreciated. Thanks all in advance.

    maybemedic wrote:
    Mogalr,
    The non numeric chars could be any random chars like aabb,null strings etc.In the past I've made small methods that would just check to see if the string was all characters and decimal point... and check formatting... check that it doesn't have 2 decimal points and after it's trimmed that there aren't any spaces and the length is >0.
    The checking is slower than using like Double.doubleValue(), unless you hit a format exception. So you have to decide what quality of data you have before committing to you're game plan.

  • Scanner cant find the text file??

    Hello guys,
    I have a java program that is designed to generate maze out of text files. So basically it takes a text file and uses the info to set up a maze through GUI. The program was written by my professor and i cant get it to run the text files. When i run the program a gui pops up and assks me to enter one of eight text files.
    They are labeled maze1.txt to maze8.txt
    So once i enter the file, the programs tells me that the files can not be found. I have all eight maze files saved in the source folder. So i assume i dont have to import anything. If it helps any here is how the project set up looks like in eclipse? I have to assume that i have not set up something correctly as the program should work.
    Here is the pic of my eclipse setup:
    [http://img.photobucket.com/albums/v395/merlin77/maze.jpg]
    What am i doing wrong?
    Thanks for your help,
    Edited by: Lovac on Oct 8, 2008 10:05 PM

    Sorry i should have provided more information. Here is how his constructor for Maze class looks like:
         public Maze(String fname) throws FileNotFoundException {
              Scanner sc = new Scanner(new File(fname));
              int r, c;
              r = sc.nextInt();
              c = sc.nextInt();
              m = new int[r + 2][c + 2];
              for (int j = 0; j < c + 2; j++) {
                   m[0][j] = -1;
                   m[r + 1][j] = -1;
              for (int i = 0; i < r + 2; i++) {
                   m[0] = -1;
                   m[i][c + 1] = -1;
              for (int i = 1; i <= r; i++) {
                   for (int j = 1; j <= c; j++) {
                        m[i][j] = sc.nextInt();
              sc.close();
    As you can see above the text file is just passed to constructor as a parameter, and i am thinking when i run the program and it asks me for the text file, i just give it the file name ex. "maze1.txt" and that would be the parameter to the Maze constructor. BUT then the constructor fails to find the file and from what i know that is due to files eather not being imported in the java class or because they are missing from the source folder?
    But clearly i have them in the source folder, so importing them in java class would be pointless. The compiler should be able to find them in the source folder.
    I guess i can forward this question to Professor, but i thought there was something simple that i am missing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How can I use sql loader to load a text file into a table

    Hi, I need to load a text file that has records on lines tab delimited into a table. How would I be able to use the sql loader to do this? I am using korn shell to do this. I am very new at this...so any kind of helpful examples or documentation would be very appreciated. I would love to see some examples to help me understand if possible. I need help! Thanks alot!

    You should check out the documentation on SQL*Loader in the online Oracle document titled Utilities. Here's a link to the 9iR2 version of it: http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/server.920/a96652/part2.htm#436160
    Hope this helps.

  • Using counter to time stamp to text file

    Dear all,
    I am using counter to acquire singnal from quadrature linear encoder. I would like to time stamp the data acquisition to text file but I found that I can't choose to read time. Anyone know how to solve this problem?
    Attachment is my program.
    Thank you very much!
    Best regards,
    George
    Attachments:
    encoder continous 21-4-2013.vi ‏28 KB

    Hi,
    Have you seen these two articles?
    http://digital.ni.com/public.nsf/allkb/68806B93A21​355E98625726F0064822B
    http://digital.ni.com/public.nsf/allkb/5D42CCB17A7​0A06686256DBA007C5EEA
    Basically, it can be done, but be aware it may not be as accurate as you would like.  Follow the code in the first article and note that the easiest way would be to just use the basic File I/O VIs to write to text file, since the Write to Measurement File VI will only work with waveforms and you have counter output.
    Matt Lee
    National Instruments
    Applications Engineer

  • Issues with cs5.0.03- cannot use CUDA, cannot find cuda support text file

    Hi,
    I am working with a big project and recently upgraded my video card to a GTX 570.
    I cannot enable the CUDA engine in project settings, it is completely greyed out..  Doing some searches, everyone seems to point at a cuda support text file...
    Kicker 2-
    I go to the Root directory of where adobe is installed, see the CS5 folder- with NO Cuda supported list.... Do a complete search of the whole machine, nothing.
    Updated adobe, no change
    Most up to date video drivers from Nvidia are already installed. 
    Went through Nvidia control panel to manually set it to render using the GPU- no change...
    I am at a loss here, any ideas or help would be much appreciated.

    Hello,
    Thank you for your time-
    Ok, I remoted back into the machine and took a closer look again,  Somehow half of the CS5 suite is on the C drive, and the other is on the storage- CS5 primarly. How I personally do not know, but from there was able to locate the needed folders, and created the text file.  All is well now, I just told them to finish the project first, before we move it over where it belongs.
    Joe Bloe P. Thank you very much.

  • How different Web Services can use a class which parses an XML file

    I am using RAD6.1 for developing and deploying web services.As I am using 15 web Services which uses a common class which is used to parse an XML file.As this XML file should be parsed only once and should be used by all the web services.I have made this common class as Singleton but it works as singleton for only one webservice and for other web service again it is parsing the xml file.I want to parse this xml file only once and used by all the web services.In my case tis file is parsed 15 times for 15 web services, but it should be parse donly once and used by all 15 services.Please give me the solution.
    Thanks and Regards
    Sayeeduzzaman

    Hello,
    the 15 Webservices should have a static attribute which contains the xml:
    private static String xml;
    then initialise the xml like this:
    if (xml == null)
    xml = parseIt();
    else
    //do nothing, XML already initialised!
    }

  • How to parse a text file and produce a dynamic shell script for linking?

    I have some mapping files, one example is like this one;
    $ cat CON_xfrm_contract_to_20080302.map
    (object mfile_c_type
    (path "file:OBSOLETE")
    (fs "file://amanos/s01/abinitio/data/prod/mfs/mfs_16way")
    (local_paths 16
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_001/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_002/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_003/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_004/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_005/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_006/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_007/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_008/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_009/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_010/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_011/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_012/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_013/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_014/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_015/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"
      "file://amanos/s01/abinitio/data/prod/mfs/parts/mfs_16way_016/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat"))In this file's content I have some exracted text files with same names under different folders;
    $ ls -lt /s01/abinitio/data/prod/mfs/parts/mfs_16way_*/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat   [
    -rw-rw-rw-   1 ab_live  abinitio 438652105 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_010/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438490410 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_016/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438219252 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_007/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438521432 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_014/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438488130 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_003/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438249547 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_002/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438312177 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_012/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 439074566 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_015/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438722261 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_004/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438742477 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_001/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438517268 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_008/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438645835 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_011/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438334994 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_006/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438470743 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_005/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438095853 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_009/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    -rw-rw-rw-   1 ab_live  abinitio 438434204 Mar  3 01:42 /s01/abinitio/data/prod/mfs/parts/mfs_16way_013/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.datI need a shell script which will produce a shell script from the content of the mapping file so that I can be able to symbolicly link these files with different names and under the same folder, like;
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_001/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat ./mfs_16way_001.CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_016/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat ./mfs_16way_016.CON_xfrm_contract_to_20080302.datI am a newbie for shell scripting, I tried several awk and sed operations but couldn't get close to this output :(
    If you guide me I will be so glad, thank you.
    ps: amanos is the name of this server.

    this is thepoint that I am stuck, I can not add the destination sym.link name to the end of each line;
    $ grep "  \"file://amanos" CON_xfrm_contract_to_20080302.map | cut -c17- | sed  's/"//;s/)//g' | sed 's/\/s01/ln -s \/s01/g'
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_001/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_002/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_003/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_004/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_005/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_006/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_007/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_008/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_009/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_010/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_011/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_012/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_013/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_014/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_015/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    ln -s /s01/abinitio/data/prod/mfs/parts/mfs_16way_016/mfs_16way/Applications/RDS/CON_PUB/main/CON_xfrm_contract_to_20080302.dat
    $ /)//g' | sed 's/\/s01/ln -s \/s01/g' | awk -F\/ '{print $8"."$14}'                                                       <
    mfs_16way_001.CON_xfrm_contract_to_20080302.dat
    mfs_16way_002.CON_xfrm_contract_to_20080302.dat
    mfs_16way_003.CON_xfrm_contract_to_20080302.dat
    mfs_16way_004.CON_xfrm_contract_to_20080302.dat
    mfs_16way_005.CON_xfrm_contract_to_20080302.dat
    mfs_16way_006.CON_xfrm_contract_to_20080302.dat
    mfs_16way_007.CON_xfrm_contract_to_20080302.dat
    mfs_16way_008.CON_xfrm_contract_to_20080302.dat
    mfs_16way_009.CON_xfrm_contract_to_20080302.dat
    mfs_16way_010.CON_xfrm_contract_to_20080302.dat
    mfs_16way_011.CON_xfrm_contract_to_20080302.dat
    mfs_16way_012.CON_xfrm_contract_to_20080302.dat
    mfs_16way_013.CON_xfrm_contract_to_20080302.dat
    mfs_16way_014.CON_xfrm_contract_to_20080302.dat
    mfs_16way_015.CON_xfrm_contract_to_20080302.dat
    mfs_16way_016.CON_xfrm_contract_to_20080302.datMessage was edited by:
    antu
    Message was edited by:
    antu

  • How to use Swing html to parse a html file..

    I am currently working on a project in java.i need to read a Html file, extract the table tag along with its contents if it has a button embedded in it and replace it with another code..
    i tried it with Reg Ex in java but in vain.. Any help is great... I need an idea of how to use Html parser for this prob.. any examples will be fine..

    Run the program from command line, this way you will see the errors, if any.
    example.: java -jar theJarfile.jar
    I was successful in creating a comm application. I placed the win32com.dll in the same directory of my application jar file and all worked.
    I also extracted the comm.jar , and jar'd my app with the extracted comm files to make one jar.
    I also had a fileWriter() to get the clients jre path and my app would write the javax.properties file to the correct place.
    It took me severel weeks and late nights to accomplish this, but it was all necessary to be able to install only my app, and not a bunch of api's that were needed.

  • Using pico or nano to edit text file in ssh connection to remote osx host

    Hi everybody!
    I can not get thru to a point when I'll be able to edit files on a remote osx comuter with pico or nano editors. When I connect thru ssh and start pico it says
    Error opening terminal: network
    I am a newbie to Unix beast. Vi is too complex for me.
    Thanks,
    Maxim
    PowerBook G4 1GHz 12 40GB SD   Mac OS X (10.4.4)  
    PowerBook G4 1GHz 12 40GB SD   Mac OS X (10.4.4)  

    Maxim,
    The problem appears to be the value of your environment variable TERM. It seems to be set to network. It needs to be set to something that pico and nano will understand. Since I do not know what your shell is I need to give you two methods of setting the TERM variable. One of the methods will fail as it is not appropriate for the shell you are using. If it does, don't worry about it just try the other method.
    The first method has two commands. Note: capitalization is significant here. They are:
    TERM=vt100
    export TERM
    If those commands give an error message, use this command:
    setenv TERM vt100
    You should now be able to edit your files.
    I am using a terminal type of vt100 as it is about the simplest terminal type and is supported by just about every unix you might be using to connect to the mac as you do not provide that information.
    Hope this information helps.
    Curt

  • Parse large (2GB) text file

    Hi all,
    I would like your expert tips on efficient ways (speed and memory considerations) for parsing large text files (~2GB) in Java.
    Specifically, the text files in hand contain mobility traces that I need to process. Traces have a predefined format, and each trace is given on a new line in the text file.
    To obtain the attribues of each trace i use java.util.regex.Pattern and java.util.regex.Matcher.
    Thanks in advance,
    Nick

    Memory mapped files are faster when you need random access and you don't need to load all the data, however here it just add complexity you don't need IMHO.
    I suspect most of the time is taken by the parser so if you customise your parser it could be faster. Here is a simple custom parser
    public static void main(String... args) throws IOException {
        String template = "tr at %.1f \"$obj(1) pos 123.20 270.98 0.0 2.4\"%n";
        File file = new File("/tmp/deleteme.txt");
    //        if(!file.exists()) {
            System.out.println(new Date()+": Writing to "+file);
            PrintWriter pw = new PrintWriter(file);
            for(int i=0;i<Integer.MAX_VALUE/template.length();i++)
                pw.printf(template, i/10.0);
            pw.close();
            System.out.println(new Date()+": ... finished writing to " + file + " length= " + file.length() / 1024 / 1024 + " MB.");
        long start = System.nanoTime();
        final BufferedReader br = new BufferedReader(new FileReader(file), 64 * 1024);
        for(String line;(line = br.readLine()) != null;) {
            int pos = 6;
            int end = line.indexOf(' ', pos);
            double time = Double.parseDouble(line.substring(pos, end));
            pos = line.indexOf('s', end+12)+2;
            end = line.indexOf(' ', pos+1);
            double x = Double.parseDouble(line.substring(pos, end));
            pos = end+1;
            end = line.indexOf(' ', pos+1);
            double y = Double.parseDouble(line.substring(pos, end));
            pos = end+1;
            end = line.indexOf(' ', pos+1);
            double z = Double.parseDouble(line.substring(pos, end));
            pos = end+1;
            end = line.indexOf('"', pos+1);
            double velocity = Double.parseDouble(line.substring(pos, end));
        br.close();
        long time = System.nanoTime() - start;
        System.out.printf(new Date()+": Took %,f sec to read %s%n", time / 1e9, file.toString());
    {code}
    prints
    {code}
    Sun May 08 09:38:02 BST 2011: Writing to /tmp/deleteme.txt
    Sun May 08 09:42:15 BST 2011: ... finished writing to /tmp/deleteme.txt length= 2208 MB.
    Sun May 08 09:43:21 BST 2011: Took 66.610883 sec to read /tmp/deleteme.txt
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Parse TEXT File??

    Hi,
    I am using CF 8
    I have a text file (mylog.txt) that currently stores login
    information for our users. I need to parse and extract some basic
    information from the file and I am having a hard time. I need to
    know the following
    1. A list of all UNIQUE email addresses that appear in the
    text file.
    2. A count of how many times each email address appears
    Each time a user logs on a "new line" is entered in the text
    file. Here is some sample data:
    [1/05/08 1:15:31 PM] User [email protected] logged in.
    [1/11/08 3:57:30 PM] User [email protected] logged in.
    [1/12/08 8:33:17 PM] User [email protected] logged in.
    [2/17/08 6:37:07 AM] User [email protected] logged in.
    [2/19/08 3:57:30 PM] User [email protected] logged in.
    I would like to parse the text file and then output my
    results to the screen. The output should look like this, note John
    logged in twice:
    Email Address | Count
    [email protected] 1
    [email protected] 2
    [email protected] 1
    [email protected] 1
    The prior user here should have stored this in the database
    but for now I still need to get at this data.
    Any help appreciated.
    Thanks,
    -Westside

    You can use cfhttp to convert your file variable to a query
    and use query of queries to count email adddresses.

  • Parsing text file with SGML tags

    <EMAIL>
    <ADDRESS>>[email protected]
    <DESC>>Email your questions to Click Here to E-mail
    <POP>
    <ADDRESS>N/A
    <ZIP>N/A
    How do you parse above text file which has SGML tags ? thanks

    Oh, sorry, if it's not an XML-file, then you properbly should use another approach. Where does the file come from? Could you properbly make it be a xml file ? ;-)
    Possible approaches are:
    * StringTokenizer, possibly with returning delimiters option enabled
    * good old make-it yourself indexOf/substring-method, ok... complicated
    * if you would like to handle the contents exactly like xml you could add a <?xml version="1.0"?><root> in the beginning and a </root> in the end and still use an xml parser, but keep character encodings in mind here.
    * another quite simple way that properbly fits best is java.util.regex API. if you want to use it, I can give you the code. it's easy.
    regards
    sven

Maybe you are looking for