Reputation: 13
Input Name Rico
Address Australia
Age 24
Name Rica
Address Asia
Age 25
Output Name Rico, Address Australia, Age 24
Name Rica, Address Asia, Age 25
Can we do this in Unix?
Upvotes: 0
Views: 67
Reputation: 13
I found the solution:
awk 'BEGIN { RS="" ; FS="\n"}; { print $1,$2 }' file
This sets the input record separator as a blank line, or consecutive blank lines for this matter, as the next record will be next non-blank line. This also sets the field separator as nextline.
Upvotes: 0
Reputation: 1802
You can do converting multiple lines to single line with using awk.
#!/usr/bin/awk
# table.awk
{
if (NR == 1) {
printf("%s",$0);
} else {
printf(",%s",$0);
}
}
$ cat input.csv
Name Rico
Address Australia
Age 24
Name Rica
Address Asia
Age 25
$ awk -f table.awk input.csv
Name Rico,Address Australia,Age 24,Name Rica,Address Asia,Age 25
There are more efficient answers in Stackoverflow, like following:
How to merge rows from the same column using unix tools
Upvotes: 0