Reputation: 67
I have a set of data name Book.txt and i would like to display them in shell. However im having problems trying to group my data in column with specific delimiter
Book.txt contains:
Harry Potter 1:Author1:100
Lord Of The Rings:Author2:200
Im able to display the data in Book.txt with the following code:
awk -F':' '{print $1 "\t" $2}' ./Book.txt
However i would like them to be arrange nicely in columns so i tried using pipeline column
awk -F':' '{print $1 "\t" $2}' ./Book.txt | column -s "/t"
But when i tried it, it doesnt seem to work. I couldnt use column -t as my title has whitespace and it acts as a delimiter. I would like to use 'tab' as my delimiter instead
Upvotes: 2
Views: 4260
Reputation: 85775
This accounts for the header and the removal of the last column:
$ cat file
Book Header
Harry Potter 1:Author1:100
Lord Of The Rings:Author2:200
$ awk -F':' -v OFS=':' '{print $1, $2}' file | column -s: -t
Book Header
Harry Potter 1 Author1
Lord Of The Rings Author2
Upvotes: 1
Reputation: 1609
Can you use directly the column
command?
column -s ":" -t Book.txt
Result:
Harry Potter 1 Author1 100
Lord Of The Rings Author2 200
Upvotes: 5