Hi All,
I had a file called Input.txt, i need to group up in a single line as 1=ttt and the no of lines may vary bewteen the 1=ttt
cat Input.txt
1=ttt,2=xxxxxx, 3=4545
44545, 4=66667
7777, 5=77723
1=ttt, 2=xxxxxx, 3=34436 66
3545, 4=66666, 5=ffffff, 6=uuuuuuu
1=ttt, 2=xxxxxx, 3=311343545, 4=66666
1=ttt, 2=xxxxxx, 5=XAXAXA, 7=FDFD
O/p :
1=ttt,2=xxxxxx, 3=454544545, 4=66667 7777, 5=77723
1=ttt, 2=xxxxxx, 3=34436 663545, 4=66666, 5=ffffff, 6=uuuuuuu
1=ttt, 2=xxxxxx, 3=311343545, 4=66666
1=ttt, 2=xxxxxx, 5=XAXAXA, 7=FDFD
danmero
November 11, 2008, 10:02am
2
Try awk
awk 'NR!=1 && $1 ~ /1=/{printf "\n"}{printf}' file
Hi,
It gives error as,
awk: syntax error Context is:
>>> NR!=1 && $1 ~ /1=/{printf "\n"}{printf} <<<
i had changed the printf to print and tried, o/p as
awk 'NR!=1 && $1 ~ /1=/{print "\n"}{print}' Input.txt
1=ttt,2=xxxxxx, 3=4545
44545, 4=66667
7777, 5=77723
1=ttt, 2=xxxxxx, 3=34436 66
3545, 4=66666, 5=ffffff, 6=uuuuuuu, 7=ooooooo
1=ttt, 2=xxxxxx, 3=311343545, 4=66666
1=ttt, 2=xxxxxx, 5=XAXAXA, 7=FDFD
Hey, i had tried in nawk.. its working fine..
Thanx
perl:
undef $/;
open FH,"<a" or die "Can not open file";
$str=<FH>;
$str=~tr/\n//d;
@arr=split("1=ttt",$str);
print "1=ttt$_\n" foreach(grep { length($_)>1 } @arr);
close FH;