I have a file where I need to join consecutive lines. The twist is that the number of lines to join together varies. An example file is:
TAG ,
Attribute1 ,
Attribute2 ,
Attribute3 ,
TAG ,
Attribute1 ,
TAG ,
Attribute1 ,
Attribute2 ,
Attribute3 ,
The TAG is consistent ( i.e. the same string) and I need to join all the attribute lines to the TAG line for each occurence of TAG as below.
TAG ,Attribute1 ,Attribute2 ,Attribute3 ,
TAG ,Attribute1 ,
TAG ,Attribute1 ,Attribute2 ,Attribute3 ,
I've been trying with sed and have got this script
/TAG/,/Attribute/{
/^TAG/N;s/\n/ /g
}
So I'm defining the block of text I want to operate on and then keep adding to the multiline and change carriage returns to space. This works up to a point in that the entries with 1 attribute is joined ok, however the multiple attribute lines only joins the first attribute. i.e.
TAG ,Attribute1 ,
Attribute2 ,
Attribute3 ,
TAG ,Attribute1 ,
TAG ,Attribute1 ,
Attribute2 ,
Attribute3 ,
Any clues as to what this final step should be would be greatly appreciated.
I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams
TAG ,
Attribute1 ,
Attribute2 ,
Attribute3 ,
TAG ,
Attribute1 ,
TAG ,
Attribute1 ,
Attribute2 ,
Attribute3 ,
The TAG is consistent ( i.e. the same string) and I need to join all the attribute lines to the TAG line for each occurence of TAG as below.
TAG ,Attribute1 ,Attribute2 ,Attribute3 ,
TAG ,Attribute1 ,
TAG ,Attribute1 ,Attribute2 ,Attribute3 ,
I've been trying with sed and have got this script
/TAG/,/Attribute/{
/^TAG/N;s/\n/ /g
}
So I'm defining the block of text I want to operate on and then keep adding to the multiline and change carriage returns to space. This works up to a point in that the entries with 1 attribute is joined ok, however the multiple attribute lines only joins the first attribute. i.e.
TAG ,Attribute1 ,
Attribute2 ,
Attribute3 ,
TAG ,Attribute1 ,
TAG ,Attribute1 ,
Attribute2 ,
Attribute3 ,
Any clues as to what this final step should be would be greatly appreciated.
I love deadlines. I like the whooshing sound they make as they fly by - Douglas Adams