How to words in arrange as Table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to words in arrange as Table
# 1  
Old 08-18-2012
How to words in arrange as Table

Hi Team,

I have one file in that almost 100+ words in lines

Eg:-

Code:
Unix
windows
solaris
Linux
...
...

But I want arrange all lines in table format and can able read on screen

Eg: -
Code:
Unix         windows    solaris   Lunix......
Hp unix     Mac-os ......

Like as Table... Please help me how to do ( I think sed or awk is good... no idea)

Thanks for your help.


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-18-2012 at 06:59 PM.. Reason: code tags
# 2  
Old 08-18-2012
Try paste with the appropriate number of delimiters, e.g. -d ' \n'
# 3  
Old 08-18-2012
HI Rudic,

Still I can see only lines after use
PHP Code:
-'\n' 
, but, If use -s I am serial lines with only once character space.

Code:
$cat tmp.txt
unix
windows
solaris
MacOS
$

Code:
 
 
$ paste -d '\n' tmp.txt
unix
windows
solaris
MacOS
$

Code:
 
PHP Code:
-
Gives serial words with single space $ paste -s tmp.txt unix windows solaris MacOS $

# 4  
Old 08-18-2012
Joins into ten columns per record:

Code:
awk '
    {
        if( c > 10 )        # 10 columns; customise as needed
        {
            printf( "\n" );
            c = 0;
        }
        printf( "%s%s", c++ ? "\t" : "", $1 );
    }
    END { printf( "\n" ); }
' input-file

# 5  
Old 08-18-2012
Code:
sed 's/.*/"&"/' file | xargs -n4 printf '%-15s %-15s %-15s %-15s\n'

Regards,
Alister

Last edited by alister; 08-18-2012 at 11:49 PM..
# 6  
Old 08-19-2012
Quote:
Originally Posted by Bhaskar Alagala
HI Rudic,
.
.
.
Code:
 $ paste -d '\n' tmp.txt
unix
windows
solaris
MacOS
$

You're almost there. Make it -d' \n' or -d'\t\t\t\n', i.e. as many delimiters (space or TAB or linefeed) as you want columns, and you win!
# 7  
Old 08-19-2012
Let me know if this did not meet your requirement...
Code:
 awk '{ORS="\t";}1' file_name

And if you want to limit the columns...
Code:
awk '{if(NR%4==0){ORS="\n"} else {ORS="\t"}}1' file_name

change the above boldened number to set number of columns to whatever you desire...

Last edited by msabhi; 08-19-2012 at 05:16 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

2. Shell Programming and Scripting

sed command to arrange words

Hi I have a text file as given below: Input format I have a text file as given below . This is a (9 Replies)
Discussion started by: my_Perl
9 Replies

3. Shell Programming and Scripting

Gawk gensub, match capital words and lowercase words

Hi I have strings like these : Vengeance mitt Men Vengeance gloves Women Quatro Windstopper Etip gloves Quatro Windstopper Etip gloves Girls Thermobite hooded jacket Thermobite Triclimate snow jacket Boys Thermobite Triclimate snow jacket and I would like to get the lower case words at... (2 Replies)
Discussion started by: louisJ
2 Replies

4. Shell Programming and Scripting

Arrange data in table

Hello All, I have following data into my file named record. Name City phone number email Jhon Newyork 123456987 jhon@gmail.com Maria Texas 569865612 Maria_Sweet@rediffmail.com Chan Durben NA Chan123@gmail.com The output should be in straight columns.. There should not be any... (1 Reply)
Discussion started by: Nakul_sh
1 Replies

5. Shell Programming and Scripting

Arrange data in table

Hello All, I have following data into my file named record. Name City phone number email Jhon Newyork 123456987 jhon@gmail.com Maria Texas 569865612 Maria_Sweet@rediffmail.com Chan Durben NA Chan123@gmail.com |---------------------------------------------------------------| |Name ... (2 Replies)
Discussion started by: Nakul_sh
2 Replies

6. Programming

Arrange word in table metrix format

Hello everyone, I have some problem about this code : #!/usr/bin/env python import sys try : filename = sys.argv except : print 'Specify filename' sys.exit() fd = open(filename) lines = fd.xreadlines() compare = {} for line in lines : split_line =... (1 Reply)
Discussion started by: awil
1 Replies

7. Shell Programming and Scripting

Find and arrange words with same letters from list

I am making a word game and I am wondering how to find and arrange words in a list that have the same letters. In my game, you are presented with 5 letters, and you then have to rearrange the letters tp make a word. So the word could be "acorn", but those 5 letters could also make up "narco" or... (2 Replies)
Discussion started by: hellobard
2 Replies

8. UNIX for Dummies Questions & Answers

Grep.Need help with finding the words which start at [A-K] letters in thesecond column of the table

Hi buddies ! I need some help with one grep command :) I have this table: 1 Petras Pavardenis 1980 5 08 Linas Bajoriunas 1970 10 3 Saulius Matikaitis 1982 2 5 Mindaugas Stulgis 1990... (1 Reply)
Discussion started by: vaidastf
1 Replies

9. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

10. Shell Programming and Scripting

Arrange Data in table and send by mail

Everybody, can you tell me how express about this; we have text data file as : parameter1 Parameter2 AA 55 BB 77 . . . . . . We want to draw table for this data as attached then send as body of Email (4 Replies)
Discussion started by: xjklop2009
4 Replies
Login or Register to Ask a Question