AWK record in multiple lines

Hi everyboby

this is my problem

I Have this input

1111;222
222
2;333
3333;4444


111;
22222;33
33;
444

and I need this output

1111;2222222;3333333;4444
111;22222;3333;444

thank 's a lot
N.B. every output record has 4 fields

Try this:

awk '$1=$1{gsub(" ","")}1' RS= file

Use nawk or /usr/xpg4/bin/awk on Solaris if you get errors.

Something like this ?

  
sed '/^$/d' inputfile | awk 'NR%4 > 0 {a=a $0;next} {b=a $0; a=""; print b}'

Assumed that the record is splitted into 4 lines.

Great Franklin, Your solution works fine.

thank's ..... but I don t known if the record is splitted into 4 lines ..
It could be splitted like this
X;1111;222
222
2;333
3333;4444

X;111;22222;3333;444
4444

and I need
X;1111;2222222;3333333;4444
X;111;22222;3333;4444444

I only know that if the record is Good it has NF defined and next record will start with X

thanks you very much

Franklins solution works great in all the situations.

unfortunately not in my solution ... because Franklins use newline to identify next record

1111;222
222
2;333
3333;4444
111;
22222;33
33;
444

it's converted in

1111;2222222;3333333;4444111;22222;3333;444

but i know output NF = 4
so I need

1111;2222222;3333333;4444
111;22222;3333;444

thanks panyam and thanks franklin

agritur,

Based on your previous post , i assumed that , if the record is Good it shoud start with "X", based on that:

 
awk '$1=$1{gsub(" ","");$0="X"$0}1' RS="X"  input_file

Do you mean that every record has 4 fields?

---------- Post updated at 03:51 PM ---------- Previous update was at 03:45 PM ----------

Assuming all records are compete (four fields each and the fourth field is never NULL):

awk -F\; '{ r = r ? r $0 : $0 }
split(r, t) == 4 && t[4] { 
  print r; r = "" 
  }' infile

Try:

awk '!NF { print "\n";; } {ORS=""; print; } ' file

My first solution was based on the input file you provided with 2 empty lines between the records.
Not my fault.

Try this:

awk -F";" '{ORS=(NR%4)?"":"\n"}1' file

It was my fault Franklin ! touch�
input:

1111;222
222
2;333
3333;4
444
111;
22222;33
33;444

I had
1111;2222222;3333333;4
444111;22222;3333;444
:frowning:

i 'd like this
1111;2222222;3333333;4444
111;22222;3333;444

ps everybody
thank for your help

And what is the pattern to follow? The leading 111?

Yet another format of your input file?

No all , always the same format input:

my input is splitted in 1 or more lines ..... for exaple NF=4

... the output has the record completed in just a row

the awk script I think it's something like this

#!/bin/awk -f
BEGIN {
   FS=";";
   FLDmax=4;
}
{
   while (NF < FLDmax) {
      getline record;
      $0 = $0 record
   }
   print $0
}    

... what do you this about this ...

ps sorry my english it's not so good.

awk '{ORS=(NR%4)?X:RS}1'  infile

put this in "script" filename

#!/usr/bin/perl -w
while(<>){next if /^\s*$/;s/\n//;$line.="$_"}
$line=~s/4([^4])/4\n$1/g;print "$line\n";

to launch:
./script inputfile