Hey guys, i am using awk to display my information in a certain order.
Database :
Code:
Persia:42:John
France:50:Mabel
Persia:50:Rach
Germany:60:John
My expected output is :
Code:
Title Price Author
Persia 42 John
France 50 Mabel
Persia 50 Rach
Germany 60 John
So i first tried using awk command which goes like this :
Code:
Title=$(awk -F":" '{printf"\n" $1 }' fruit)
Price=$(awk -F":" '{printf"\n" $2 }' fruit)
Author=$(awk -F":" '{printf"\n" $3 }' fruit)
Reason being, i was thinking by arranging the variables under the each Columm name such as Title, Price and Author, it will arrange itself neatly. Let me show u what i meant.
Code:
echo Title Price Author
echo $Title $Price $Author
but for some reason, when i save the results in a variable, the formatting will be gone, instead of displaying the information in a neat columm, it displays the information on one line like the example below :
Code:
Title Price Author
PersiaFrancePersiaGermany
I tried using cut command but it also gives me the same problem. If i do not assign it to a variable, how am i able to format it to display it in the correct format?