Results 1 to 6 of 6

Thread: Finding field separator in a text file

  1. #1
    Join Date
    Feb 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Finding field separator in a text file

    Hi

    I want to find the field separator in a text file. Normally our text files will have these , | \t field separators. How can i find it. Using Shell script or Perl script.



    Regards / Thanks

    Swaroop Kumar. Tata
    List Management Team [ Ybrant Technologies ]
    Mail: swaroop@ybrant.com | swaroop@ybrantinc.com

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I don't understand the question. You want to find out what the field seperator is? That's what you seem to be saying, yet you later specify that the field seperator is | \t.
    Whatever you're doing, a creative use of grep(1) and awk(1) should do the trick. See the manpages for more info.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Thanks for your reply. But what exactly i have asked is.

    I have text file as input
    I want to find the field separator in the text file.
    Ususally the field separators will be , [ Comma ] or | [ Pipe ] or \t [ Tab ]

    How can i do dis.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Ah, I see.
    Well, it's very difficult to do this unless you already have some more info about the file (how many fields does it have per record? Does it use any possible field seperators in the data?)
    If neither of these are consistent throughout your files, you'll be forced to just try them all until you get data that makes sense.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jan 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Similar

    Hi, I also have a similar problem.
    I work for a company who use a pearl render program to generate WebPages.
    They have a bespoke method of coding the web pages (an example of code can be found below)
    The problem I have is the fields of the WebPages are outputted to software called Peregrine Service Centre. But when you have a complex form with a hundred or more fields, its impossible to keep a track of fields you may have missed in the template for service centre.

    An Example of code is as follows:

    -180|label||||Work Location|
    |input|CustomerWorkAddress|4|30||


    This would output:

    Work Location [CustomerWorkAddress]
    (see attachment example.bmp)
    Note. [] is a input field in a form.
    In the code above the first line creates The title of the field displayed on the form.
    The second line indicates the field.

    The | (Pipes) divide information for the attribute, there are always 6 ‘|’ to an attribute on the form acting as separators for the specification for the attribute.

    In the first line:
    ‘-‘ Indicates a new line
    ‘180’ indicates the width of the attribute
    ‘label’ which implies the field type to be a label on the form.
    ‘Work Location’ that is the label to be displayed.

    In the second line:
    There is no – indicating no new line.
    ‘input’ indicating the type of field to be an input text box.
    ‘CustomerWorkAddress’ is the field name, which will contain the value of the input.
    ‘4’is the number of lines the input box covers
    ‘30’ is the field width.

    Being quite new to programming, I need to identify all the field names and place them into a text file between ‘**’ (two stars). I.e. *CustomerWorkAddress*.

    Can anyone think of a way to do this?
    Thanks in advance. Saff

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I would seriously suggest using a database instead. If you don't have access to a database server, you could try SQLite, which saves a database as a simple file. If it's necessary to have this format for your bespoke software, it shouldn't be too hard to reconstruct it from the database, after changes have been made.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •