Removing inserted newlines from a fileld of fixed width file.
Hi champs!
I have a fixed width file in which the records appear like this
As you see, the record for 33333 is split into two records because of newline inserted in description of 33333. I want these extraneous newlines from description field to be removed for records where ever they appear in the file.
Clues can be : check the file for length 11 -32 for each record and if newline is present strip it off.
Any other solution is welcome too.
I want the output to be :
- it is not fixed that line break will appear after 'description' only..it can appear anywhere in the second field.But it is sure that it will appear in second field only, incase it appears.
- This is just the sample record for understanding, code should not be dependent on it.The code can be dependent on positioning if required.
It is a fixed width file that means each filed is identified by length in the record.
Please let me know if you need more clarification.
Last edited by enigma_1; 08-18-2009 at 06:55 PM..
Reason: code tags, PLEASE!
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Thank You.
The UNIX and Linux Forums
---------- Post updated at 05:54 PM ---------- Previous update was at 05:38 PM ----------
something to start with...
'len' is a known/expected length of ALL the records (assuming they are of the same length) - defaulted to '73'.
Assumption: there's only ONE extra new-line per 'broken' record.
nawk -f enigma.awk myFile
OR
nawk -v len=63 -f enigma.awk myFile
The code you provided worked for me for the records broken into two.
But I have some more problems. Hope you can help.
As ytou mentioned in your assumption that record is divided into two records only.
Unfortunately In my file I have just one record which is divided into three records.
Sample:
which needs to be :
Can we have some modification to the enigma.awk program to take care of record break to three records?? If I can ask for more, Can we have the code to take care of any level of record break heirarchy for each record?
I guess you need some identification for each records start.
In my file each new record starts from column(length)= 16. If any record starts from before length 16, it is continuation of previous record.
Thank u so much .Its working fine as expected.
---------- Post updated at 03:41 PM ---------- Previous update was at 01:46 PM ----------
I need one more help.
I have another file(fixed length) that will get negative value (ex:-00000000003000) in postion (98 - 112) then i have to... (6 Replies)
I have a fixed width file of length 53. when is try to get the lengh of the record of that file i get 2 different answers.
awk '{print length;exit}' <File_name>
The above code gives me length 50.
wc -L <File_name>
The above code gives me length 53.
Please clarify on... (2 Replies)
Hi All ,
I have a requirement where I need to remove duplicates from a fixed width file which has multiple key columns .Also , need to capture the duplicate records into another file .
File has 8 columns.
Key columns are col1 and col2.
Col1 has the length of 8 col 2 has the length of 3.
... (5 Replies)
Hi Guys
I am checking the treads to get the answer but i am not able to get the answer for my question.
I have two files. First file is a pattern file and the second file is the file i want to search in it. Output will be the lines from file2.
File1:
P2797f12af 44751228... (10 Replies)
Hi All,
I have created a script which generates FIXED-WIDTH file by executing Oracle query.
SELECT RPAD(NVL(col1,CHR(9)),20)||NVL(col2,CHR(9))||NVL(col3,CHR(9) FROM XYZ
It generates the data file with proper alignment. But if same file i transfer to windows server or Mainframe... (5 Replies)
I am trying to remove a line feed (\n) within a fixed width record. I tried the tr -d ‘\n' command, but it also removes the record delimiter. Is there a way to remove the line feed without removing the record delimiter? (10 Replies)
I am trying to parse a Fixed width file with data as below. I am trying to assign column values from each record to variables. When I parse the data, the spaces in all coumns are dropped. I would like to retain the spaces as part of the dat stored in the variables. Any help is appreciated.
I... (4 Replies)
Hi ,
I have a file :
CSCH74000.00
CSCH74000.00
CSCH74100.00
CSCH74000.00
CSCH74100.00
CSCH74000.00
CSCH74000.00
CSCH74100.00
CSCH74100.00
CSCH74100.00
I have to put a delimiter( say comma) in between after 6th character:
CSCH74,000.00
CSCH74,000.00
CSCH74,100.00 (2 Replies)