The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 08-27-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 610
cat file | xargs -n <number of items in a row>


Code:
"/home/tdreader" > cat t.txt
1 2 3 4 5 6 7 8 9 12 12 32 5 66 56 343 8 875 434 0
"/home/tdreader" > cat t.txt | xargs -n 3
1 2 3
4 5 6
7 8 9
12 12 32
5 66 56
343 8 875
434 0

If it is a file with one number in a line,
go for this


Code:
cat filename | tr '\n' ' ' | xargs -n 3