I have a file which consists of repeated field values on separate lines. I want to convert it so that the values are on the same line separated by a pipe char (& then a new line for each new record). e.g. my original file is
and I want it to look like:
The only way I can think of doing this is to use split (to split into a series of files 3 lines long); tr (to translate the end of line char to '|'; cat (to put the files back together. But I know this is a poor way of doing it. I'm guessing there's a way to do the same in awk, or maybe use sed somehow - but my skills don't go that far.
Can anyone suggest an efficient - & hopefully understandable/maintainable - way of doing it?
Thanks, Chris
Code:
4
The Beatles
Liverpool
5
The Rolling Stones
London
3
The Who
London
and I want it to look like:
Code:
4|The Beatles|Liverpool
5|The Rolling Stones|London
3|The Who|London
The only way I can think of doing this is to use split (to split into a series of files 3 lines long); tr (to translate the end of line char to '|'; cat (to put the files back together. But I know this is a poor way of doing it. I'm guessing there's a way to do the same in awk, or maybe use sed somehow - but my skills don't go that far.
Can anyone suggest an efficient - & hopefully understandable/maintainable - way of doing it?
Thanks, Chris