CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2010
    Posts
    1

    Read line by line count and then concat

    Hi Team,

    I have a source files in unix as below.

    1111111111111111----------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    -----------------------------------------------------------!20000UNKNOWN ACCOUNT

    Here - (dash) represents the null value.

    The problem with this file is a record is 540 characters long which is divided into multiple line, 80 characters each.

    I want to first replace null with space till 8 characters, no matter where the NULL value is. It could be at beginning (ex last line) or at end (first line) or at the middle of the line.

    Once replaced, i want to read line by line and count the characters. Once the count reaches 540, it should CONCAT all characters and redirect to new file.

    For example, in above case, the first record starts at 1... till ! AT 7TH line. And second record starts at 200... from 7th line till 540 characters.

    I have tried using UNIX shell script, but could not able to replace NULL with space. I have heard that it is possible using java script.

    If anyone can help me... highly appreciate. (I am not java person, working on Oracle DB).

    Thanks,
    Amit

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: Read line by line count and then concat

    This is not the kind of work that JavaScript is designed for. JavaScript is designed to run in your browser, and has limited access to system resources and I/O (and for a good reason, you don't want every web site having unfettered access to your hard drive). If all you are having trouble with is the replacing of the "-" with " ", then you should look at regular expressions in shell scripting. There are tons of pages out there with examples.

  3. #3
    Join Date
    Jun 2007
    Location
    Aurora CO USA
    Posts
    137

    Re: Read line by line count and then concat

    Also the OP should post in the Scripting Forum since JavaScript is not Java.

    Now if by Java script they actually meant Java program, then they should consider posting some code and their specific issues they're having and we could help.

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Read line by line count and then concat

    - (dash) represents the null value
    What does a null value look like in a file?
    I would think that null means no value or empty?
    Norm

  5. #5
    Join Date
    Jun 2007
    Location
    Aurora CO USA
    Posts
    137

    Re: Read line by line count and then concat

    What does a null value look like in a file?
    I would think that null means no value or empty?
    Typically, a null in a file is a 0 (zero). This is how I've always seen it represented.

  6. #6
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Read line by line count and then concat

    Ok, but when reading a file a byte of 0 is a byte of data with a value of 0. 0 can be a valid value for many applications.

    When reading the file, to find bytes of 0s you'd need to read bytes vs Strings.
    Norm

  7. #7
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: Read line by line count and then concat

    Actually I don't get it, how a null value can be seen in a file?

    Anyways, find the byte code of the thing you call "null value" and make a massive replace using regexp, replacing the "null values" with empty string or whatever you need (String.replaceAll({null value regexp code},"");). Also while in the loop count the non-"null value" chars. That's all...
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured