Another easy Bourne Shell Scripting question
It is very simple this time (but not simple enough for me). I have file with data entries seperated by ",".
The files looks like this.. Code:
Anderson,Sarah,02-95437869 Code:
Anderson(white space)Sarah(white space)02-95437869 I thought that I would be able to do this by adding multiple \t between each field, but the command I thought would do it, doesn't work. cat records.txt | tr "[,]" "[\t*2]" It only replaces the "," with one "\t". What could I try to do to display this data in columns, or perhaps a way to add multiple tabs? P.S has to work in bourne shell (#!/bin/sh). thanksgsg |
Another easy homework-question? :)
|
This one works for me:
Code:
#!/bin/sh |
However, it doesn't aligns well when fields have too distinct width.
Here's a try: Code:
#!/bin/sh |
Quote:
Code:
awk -F, '{printf("%-10s%-10s%-10s\n", $1,$2,$3)}' records.txt of the longest string in each column you don't have to worry about potential breaks of the structure ... Or this very simple approach :) Code:
column -t -s, records.txt Cheers, Tink |
You win !
|
Wow ... that column command is bloody brilliant!
|
Thank you everyone, and especially Tinkster, my bourne shell does not have the column program, but the awk command you listed worked perfectly.
Thanks! |
All times are GMT -5. The time now is 11:06 PM. |