Removing \n within a fixed width record

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?

what is the delimiter?

The record delimiter is also a line feed (\n)

Thanks

Can you provide a sample of the input?

cheers,
Devaraj Takhellambam

  • How long is each fixed-length record (excluding the trailing linefeed)?
  • It the data solely ASCII text (i.e. no control codes except of course the linefeeds)?
  • What shell do you use (e.g. ksh , bash etc.)?
  • What "echo" syntax does your shell use to not output a newline (e.g. "echo -n" or some other method).

I've give you an example, since data is senstive. It is a fixed width file downloaded from Mainframe via FTP. This is the what the file would look like (in Unix Env).

Col1 Char5
Col2 Char5
Col3 Char20
Col4 Char5

Expected Format:
12345abcdeMy name is Jack SmitSVY01

Actual Format
12345abcdMy name is
Jack SmitSVY01

There was an embedded (\n) after "My name is" and automatically forced a new line...furthermore, each record has a (\n) as its record delimter (not visibly shown).

I would like to remove the embedded LF (\n) BUT not the record delimiter.

Thanks

try something like. you can tweak around this as per the fixed width lenght

awk '{s=$0;if(length(s) < 35){getline; s=s$0}printf("%s\n",s)}' filename

cheers,
Devaraj Takhellambam

Thanks! your code works like a charm! (with obvious change to fix width length).

Much appreciated!!!

Hi Devaraj,

I stumbled onto another 'error', since it is a fixed length records (and when I removed the (\n) it also truncated an extra 'space' - how can I run the same awk code but instead pad an extra space to replace the \n that it removed?

Thanks!

I am not sure if I understodd you right..
Is this something you ar looking for?

awk '{s=$0;if(length(s) < 35){getline; s=s " " $0}printf("%s\n",s)}' filename

cheers,
Devaraj Takhellambam

Thanks - that is what I was looking for.

I actually have another file that has the same problem, however, its fixed width is around 750 Char - I applied the code, but an error shows that awk was 'too long'.

Is this solution restricted to character lengths?

Please advise.