Operating System - HP-UX
1837131 Members
2430 Online
110112 Solutions
New Discussion

Re: Formatting File Output

 
SOLVED
Go to solution
Jeffrey S. Bromley
Occasional Contributor

Formatting File Output

Does anyone know how to take two files and combined them so the output would have the two files listed side by side.
The only easy day was yesterday
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: Formatting File Output

Hi Jeffrey:

# paste file1 file2

See 'man paste' for more details.

...JRF...
Magdi KAMAL
Respected Contributor

Re: Formatting File Output

Hi,

As James said, paste command merge same lines of several files or subseqquent lines of one file.

#paste file1 file2
or
#paste file1 file2 file3 ... file_n

Magdi
harry d brown jr
Honored Contributor
Solution

Re: Formatting File Output


Actually to get a real nice printout, use this:

pr -t -m file1 file2
Live Free or Die
harry d brown jr
Honored Contributor

Re: Formatting File Output


Also, with pr, you can add the column width command as in "-w200". Take the longest line of file1 and the lonest line of file2, add them together to get the "-w", otherwise pr will truncate the lines to make it fit.
Live Free or Die
Praveen Bezawada
Respected Contributor

Re: Formatting File Output

HI
if you want the file content to be listed side by side

ex: a.lst
1
2
b.lst
3
4
output to be
1 3
2 4
then use the below shell

count=1
while read eachline;do
awk '{ if (NR == "'$count'"){
print "'$eachline'"" "$0
}}' b.lst
done
This will produce the desired output...

...BPK...