1827459 Members
4290 Online
109965 Solutions
New Discussion

list problem

 
SOLVED
Go to solution
Kraekel
Occasional Contributor

list problem

Hello,
I have a Liste look like
atz-25100010 BGM+785+OOLU5+9'
atz-25100010 RFF+API'
atz-25100010 DTM+232@040405
atz-25100064 BGM+785+TTNU5+5'
atz-25100064 RFF+API'
atz-25100064 DTM+232@040404
atz-251000115 BGM+785+PONU0+9'
atz-251000115 RFF+API@02.0403.0026'
atz-251000115 DTM+232@040408

my problem is that i will sort the liste to

atz-25100010 BGM+785+OOLU5+9' atz-25100010 RFF+API'atz-25100010 DTM+232@040405
atz-25100064 BGM+785+TTNU5+5' atz-25100064 RFF+API'atz-25100064 DTM+232@040404
atz-251000115 BGM+785+PONU0+9' atz-251000115 RFF+API@02.0403.0026' atz-251000115 DTM+232@040408

I can edit the Datei with vi and 3 shift J because the Datei have many entry

Can awk sort the Datei
4 REPLIES 4
Rodney Hills
Honored Contributor
Solution

Re: list problem

If you had a multiple of 3 lines in the file, then you could use-

sed 'N;N;s/\n//g'
HTH

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: list problem

Another method is to use "paste". If you don't mind have "tab" characters between the joined lines.

paste -s -d"\t\t\n" yourfile

Benefit is that if your file does not have a multiple of 3 number of records, then a partial line is still displayed.

HTH

-- Rod Hills
There be dragons...
Mark Grant
Honored Contributor

Re: list problem

Well, if you can't guarantee three entries for each one this rather embarassing bit of perl will do it.

#!/usr/bin/perl

open FILE, "
while(){
chomp;
$oldkey=$key;
print;
($key,$data)=split / /;
if($key ne $oldkey){
print "\n";
}
}
Never preceed any demonstration with anything more predictive than "watch this"
Rodney Hills
Honored Contributor

Re: list problem

If you want a one line perl routine-

perl -pe 'chomp unless /DTM/'
This joins lines until a line with "DTM", then a new line is started.

HTH

-- Rod Hills
There be dragons...