i need help using awk. Thanks
i have a file it contains the following
text.txt
The Hunger Games:Suzanne Collins:1:2:3
Weapon X:Stan Lee:3:4:5
the code that i was using to print the lines
awk -F '[:]' '{print $1, $2 ,"$"$3, $4 , $5 }' BookDB.txt
i wish for the out put to become like this
The Hunger Games Suzanne Collins 1 2 3
Weapon X Stan Lee 3 4 5
Try this to get tab spacings as in your example:
Setting
:
as field seperator and\t
as output field seperator. Then for the second line(NR==2)
, addone extra tab
for the second field. Then print the fields.Or even simpler (if it is acceptable for you):
You can pipe awk output to
column
like this:The output you show is not tab-separated, it's formatted as a table and for that all you need is:
If you really wanted it to be tab-separated then that'd be:
If you wanted specific fields:
If you don't have
column
but want tabular output, you can do it all in awk: