Click to See Complete Forum and Search --> : Read line by line count and then concat


Amit.Sagpariya
June 7th, 2010, 06:08 AM
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

ProgramThis
June 7th, 2010, 08:26 AM
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.

ajhampson
June 7th, 2010, 02:24 PM
Also the OP should post in the Scripting Forum (http://www.codeguru.com/forum/forumdisplay.php?f=70) 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.

Norm
June 8th, 2010, 01:13 PM
- (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?

ajhampson
June 8th, 2010, 01:54 PM
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.

Norm
June 8th, 2010, 02:36 PM
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.

Xeel
June 8th, 2010, 04:46 PM
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...