If someone out there could help me out with this problem. I would really appreciate it.
I am trying to convert a file into xml format using Unix shell scripts.
The file has fields with each field having a certain number of bytes, but the fields are not delimited by anything (e.g. whitespace). I need to get those fields into some sort of data structure so that I can use them to generate the XML using a simple for loop. The following is a an example of what I am looking at:
Jack Johnson 90980288Harv 9090998
Joe Joie 8989 Sed 99488
I can't use whitespace as a delimiter.
Thanks you guys very much,
I really appreciate it.
The reason I cannot use a comma as a delimiter or anything like that is because the fields are not seperated by a delimiter, but allocated a certain number of bytes.
For example:
Firstname (10) Last Name (10)
MickelsonJackonson ( You will have fields that take up all space in the field and you won't have any commas in there)
I am thinking of using the substr function from awk which will be able to read in the exact bytes from each line and then put it into an array or something to process it.
hmm similar like something I am working on myself. I need to judge the varying length of a string and create independent results. I don't think substr will work for me though, but sounds like it may be one solution for your quandary.
Thanks guys very much. I was able to use the substr function in order to read in the fixed columns. I am also considering doing the gawks' fieldwidth thing, but would that affect the performance? I am to be working on around 800,000 records so it also needs to be pretty efficient.
Also, is there is a quick function in awk that lets you strip away leading and trailing whitespace from a string? I was thinking of using the 'split' function to store the string into an array and then printing out the array, but that seems to be overkill. Any help would be appreciated.
Anything wrong with this code you see? I cannot get it to run: I am basically trying to run some awk code within a korn shell. I want to run the trim funciton, but I get complaint when I run the script.