DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Shell Scripting (http://www.daniweb.com/forums/forum113.html)
-   -   How can i set column width in unix? (http://www.daniweb.com/forums/thread148509.html)

RohitSahni Oct 1st, 2008 9:42 am
How can i set column width in unix?
 
mY QUERY IS RELATED TO..

How can i set coloumn width in unix...

Like for ex. i am having a file, whose content is like

------------------------------
aba bba baba
abba baba baaa
addd ffff fffff
-----------------------------------
i want it to be like
-----------------------------------
aba bba baba
abba baba baaa
addd ffff fffff
------------------------------------
How can i set the coloumn width in unix... Please reply asap.
Thanks

masijade Oct 1st, 2008 10:01 am
Re: How can i set column width in unix?
 
Depends on the editor.

RohitSahni Oct 1st, 2008 10:04 am
Re: How can i set column width in unix?
 
Quote:

Originally Posted by masijade (Post 702691)
Depends on the editor.

i am using vi editor,....and want to send the file genrated as a mail...and want it to be in proper format

masijade Oct 1st, 2008 10:14 am
Re: How can i set column width in unix?
 
There is no "columns" There are tab sizes, but those only apply to the current session (also saved in preferences but only for the current user), so that doesn't help as the next person/viewer/editor won't have the same settings.

You best bet is, if your good at regex, to use search and replace to add in spaces. Even better, is to modify whatever "writes" the data to do that. Anyway, for vi, here:

http://www.cs.fsu.edu/general/vimanual.html

RohitSahni Oct 1st, 2008 10:30 am
Re: How can i set column width in unix?
 
Quote:

Originally Posted by masijade (Post 702705)
There is no "columns" There are tab sizes, but those only apply to the current session (also saved in preferences but only for the current user), so that doesn't help as the next person/viewer/editor won't have the same settings.

You best bet is, if your good at regex, to use search and replace to add in spaces. Even better, is to modify whatever "writes" the data to do that. Anyway, for vi, here:

http://www.cs.fsu.edu/general/vimanual.html

Here's the solution..
awk -F"~" '{printf("%-15s%s~%s\n", $1,$2,$3)}' inputfile
ID1 Name1~Place1
ID2 Name2~Place2
ID3 Name3~Place3

Thanks guys for your help..

Gromit Oct 1st, 2008 2:10 pm
Re: How can i set column width in unix?
 
This may be late, but I wanted to get the "column" command into the fight!

$ column -t -s " " test.txt 
aba  bba  baba
abba  baba  baaa
addd  ffff  fffff

Hope this helps!
-G


All times are GMT -4. The time now is 9:40 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC