Portable way to print list in columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Portable way to print list in columns
# 1  
Old 07-31-2016
Portable way to print list in columns

so if i have a list of file names, on linux system, we can use the column command to split them up into columns.

sadly, the "columns" command does not exist on some OSes.

so i found that the pr command can also work.

but, pr tends to truncate the names. There's a way around that on Linux. You can pass a "-J" option to pr. but, this needs to work on other OSes where the pr command does not have that option.

so i'm wondering, is there another way to print a list into a specific number of columns?

desired output should be:

Code:
$ ls | egrep ecount | pr -l 1 -t -3                    
ecount.0                ecount.1                ecount.10
ecount.11               ecount.12               ecount.2
ecount.3                ecount.4                ecount.5
ecount.6                ecount.7                ecount.8
ecount.9                ecountall.0             ecountall.1
ecountall.10            ecountall.11            ecountall.12
ecountall.2             ecountall.3             ecountall.4
ecountall.5             ecountall.6             ecountall.7
ecountall.8             ecountall.9
$ 
$

# 2  
Old 07-31-2016
How about
Code:
ls -1 | paste -s -d'\t\t\n'

?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-31-2016
Quote:
Originally Posted by RudiC
How about
Code:
ls -1 | paste -s -d'\t\t\n'

?
this doesn't work on AIX:

Code:
$ 
$ ls | egrep ecount | paste -s -d'\t\t\n'
Usage: paste [-s] [-d List] file...
$ 
$

# 4  
Old 07-31-2016
Try giving the delimiters verbatim, i.e. a <TAB> char instead of \t.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use "awk" to print columns from different files in separate columns?

Hi, I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.) I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies

2. Shell Programming and Scripting

Help with print if two columns is somehow similiar

Input File: GO:0009437,GO:0006355,GO:0006351 GO:0009437 GO:0006777,GO:0032324 GO:0035433,GO:0015992,GO:0071422 GO:0009082,GO:0009097,GO:0006566 GO:0009082,GO:0006351 GO:0000160,GO:0045893,GO:0006351 GO:0006071,GO:0045892,GO:0006351 GO:0009244 GO:0009244 GO:0046417,GO:0009094,GO:0006571... (12 Replies)
Discussion started by: perl_beginner
12 Replies

3. UNIX for Dummies Questions & Answers

Print Matches to New Columns

Hi all, I have a problem that I'm struggling to resolve. I have two files that look like this: File 1 654654654 3 987987987 2 321321321 1 File 2 14NS0064 654654654 14NS0054 654654654 14NS0032 654654654 14NS0090 987987987 14NS0093 987987987 14NS0056 321321321 As you may notice,... (2 Replies)
Discussion started by: winkleman
2 Replies

4. Shell Programming and Scripting

Print output as columns

Normal grep is not working to get the output. Sample Input: newjob: abc command name: a=b+c newjob: bbc command name: c=r+v newjob:ddc newjob:kkc command name: c=l+g newjob:mdc newjob:ldc newjob:kjc command name: u=dl+g newjob:lkdc newjob:lksdc command name: o=udl+g (6 Replies)
Discussion started by: onesuri
6 Replies

5. Shell Programming and Scripting

print columns with spaces

Hi All I've a file which is similar to the one given below column1 coulmn2 column3 column4 A B C D X Y F G H I would like to get it in this format A|B|C|D ||X|Y F||G|H Is... (4 Replies)
Discussion started by: Celvin VK
4 Replies

6. Shell Programming and Scripting

Print columns from each row

I have awk command to print column 8 awk '/select/ {print $8}' which will print column 8 But I need to print 3, 5 and 8 column in a row and each column should be de-limited by "\t" Hope anyone help me quickly. (2 Replies)
Discussion started by: elamurugu
2 Replies

7. UNIX for Advanced & Expert Users

Print rows into columns

Hi, I required to print all rows into columns(some comma separated or else) till a pattern match found. Using Solaris UNIX scripting my input is like abc def ghi jkl mno END pqr stu vwx yz 123 END ... ... (7 Replies)
Discussion started by: vikash.rastogi
7 Replies

8. Shell Programming and Scripting

How to print first 'n' columns?

Hello All, I have a file of 1000 columns. I need to print only the first 100 columns in to a new file. I have tried with the following code awk -F '{ for(i=0; i<=100; i++) {printf $i}' inputfile > outputfile But this is not working, I need the output file also of the same format of the... (4 Replies)
Discussion started by: Fredrick
4 Replies

9. Shell Programming and Scripting

Print columns in a file by number list in another file

This should follow with my last post but I think it's better to start a new one. Now I have a list of numbers stored in pos.txt: 2 6 7 . . . n . . . And I need to extract (2n-1, 2n) columns from matrix.txt: ind1 A B C D E F G H I J K L M N O P Q R ... ind2 B C D E F G H... (3 Replies)
Discussion started by: Zoho
3 Replies

10. Shell Programming and Scripting

cannot print the columns i want with awk.

hi friends! i have a script where a execute a veritas command, available_media wich retrieves me a list of tapes .lst then i execute cat /tmp/listtapes.lst | grep -v VL |sed '/^$/d'|awk -F, '{print $1, $3, $4, $9} ' > /tmp/media1.lst but it prints all the columns instead of the four... (3 Replies)
Discussion started by: pabloli150
3 Replies
Login or Register to Ask a Question