- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to combine columns from 2 files into 1 file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2005 10:08 AM
тАО09-14-2005 10:08 AM
This is what I have:
file1
1 a
2 b
3 c
file 2
1 w1 w2
2 w3 w4
3 w5 w6
How do I change the 2 files above to be this:
file 3
1 a w1 w2
2 b w3 w4
3 c w5 w6
What is the best tool to use?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2005 10:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2005 10:26 AM
тАО09-14-2005 10:26 AM
Re: how to combine columns from 2 files into 1 file
#!/bin/ksh
I=1
cat f1 |awk '{print $1,$2,$3}' |while read Nvar[$I] Avar[$I] ;do
(( I = I + 1 ))
done
I=1
cat f2 |awk '{print $2,$3}' |while read W1[$I] W2[$I] ;do
(( I = I + 1 ))
done
(( MAX = I - 1 ))
I=1
while [ I -le $MAX ] ;do
print ${Nvar[$I]}" "${Avar[$I]}" "${W1[$I]}" "${W2[$I]}
(( I = I + 1 ))
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2005 10:27 AM
тАО09-14-2005 10:27 AM
Re: how to combine columns from 2 files into 1 file
Use paste to paste two file column wise..
$ paste file1 file2
a w1 w2
b w3 w4
c w5 w6
or
$ paste file1 file2 > file3
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2005 10:29 AM
тАО09-14-2005 10:29 AM
Re: how to combine columns from 2 files into 1 file
hth,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2005 04:31 PM
тАО09-14-2005 04:31 PM
Re: how to combine columns from 2 files into 1 file
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2005 05:23 PM
тАО09-14-2005 05:23 PM
Re: how to combine columns from 2 files into 1 file
# awk '{ getline ln< "file1"; print ln,$2,$3; }' file2
1 a w1 w2
2 b w3 w4
3 c w5 w6
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-15-2005 03:32 AM
тАО09-15-2005 03:32 AM