BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Showing results for 
Search instead for 
Do you mean 

rows to column

Valued Contributor

rows to column

hi Gurus ,

I have a file with entries as below:

var1:mango
quantity:w1245
season: alphanso
var1:apple
quantity:c324
season:winter
var1:cherry
quantity:b4326
season:autumn
....
......

I want the file o/p like

var1 quantity season

mango w1245 alphanso
apple c324 winter
cherry b4326 autumn
mango b67588 spring
....
...

Many thanks ,
FrogIsDeaf
3 REPLIES
Acclaimed Contributor

Re: rows to column

Assuming you have no spaces in the file and the three lines are always in that order:

awk -F:  '
{
var1 = $2
getline
quantity = $2
getline
season = $2
print var1, quantity, season
}' input-file

Valued Contributor

Re: rows to column

Hi Dennis ,

 

thank you for the reply.

I used awk -F':' and extracted the second filed and then did a #paste -d"," - - -  < details.txt , to generate the required csv.

 

Thanks once again.

 

 

FrogIsDeaf
Acclaimed Contributor

Re: rows to column

>I used awk -F':' and extracted the second field and then did a paste

 

You didn't need to use both awk and paste, you can do it all in awk by changing OFS to comma:

awk -F:  -v OFS="," ' ....