append line

hi :smiley:

i have a file 1.txt:

XREAZM02145586k05mkkk
1azeKJLM000255
kopmjjgy
XREAZMNJK015522255521144bvfyj
XREAZM01255hhfe'yg000nnn36poigujj,jjd
nnjjjlm0025962/522

i want:

XREAZM02145586k05mkkk1azeKJLM000255kopmjjgy
XREAZMNJK015522255521144bvfyj
XREAZM01255hhfe'yg000nnn36poigujj,jjdnnjjjlm0025962/522

my code:

awk '!/^XREAZM/{ORS=""}1' 1.txt

but didn't work

thank's

Hi

awk '/XREAZ/{if (x) print x;x=$0;next;}{x=x""$0;}'  file

Guru.

That code fails to handle the last set of lines.

@alister
It does work for the input OP has provided.

However, a generic solution would be :

awk '/XREAZ/{if (x) print x;x=$0;next;}{x=x""$0;}END{print x}' file

Guru.

No, it doesn't. How could it when printing is triggered by /XREAZ/ and the final line in the data does not match that pattern?

$ cat dat
XREAZM02145586k05mkkk
1azeKJLM000255
kopmjjgy
XREAZMNJK015522255521144bvfyj
XREAZM01255hhfe'yg000nnn36poigujj,jjd
nnjjjlm0025962/522
$ awk '/XREAZ/{if (x) print x;x=$0;next;}{x=x""$0;}' dat  
XREAZM02145586k05mkkk1azeKJLM000255kopmjjgy
XREAZMNJK015522255521144bvfyj

How about

$ nawk '/^XREA/ {printf "\n%s", $0;next} {printf "%s",$0}' file

Only problem is it prints a newline at the beginning.

@alister..
oops...My mistake it was..

Guru.

Hi, try this:
1,

sed -n '/^XREA/p' filename 

2,

egrep "^aaa" filename 

Another awk:

awk '/XREAZM/ && NR>1{print x}{printf $0}END{print x}' infile

great :cool:

guruprasadpr,alister,agn,skles,Scrutinizer THANK'S

skles your code don't work :rolleyes:
Scrutinizer I did not understand your code :smiley:

Hi, print x is the same as print "" (since x=""). NR>1 means line number > 1