The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Merging columns from multiple files in one file isgoed Shell Programming and Scripting 1 08-03-2008 09:54 PM
Adding Multiple Lines to Multiple Files dayinthelife Shell Programming and Scripting 2 06-04-2008 11:50 AM
contactenate columns from multiple files coolnaps Shell Programming and Scripting 2 05-03-2008 06:01 PM
combine multiple .xl file bikas_jena Shell Programming and Scripting 4 12-11-2007 04:12 PM
Compare multiple columns between 2 files stevesmith Shell Programming and Scripting 15 09-20-2006 12:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-01-2008
martva martva is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 4
Combine multiple columns from multiple files

Hi there,

I was wondering if someone can help me with this.

I am trying the combine multiple columns from multiple files into one file.

Example file 1:
Code:
c0t0d0 c0t2d0 # hostname vgname
c0t0d1 c0t2d1 # hostname vgname
c0t0d2 c0t2d2 # hostname vgname
c0t1d0 c0t3d0 # hostname vgname1
c0t1d3 c0t3d3 # hostname vgname1
Example file 2:
Code:
c0t0d0 c0t4d0 # hostname1 vgname
c0t0d1 c0t4d1 # hostname1 vgname
c0t0d2 c0t4d2 # hostname1 vgname
c0t1d0 c0t6d0 # hostname1 vgname1
c0t1d3 c0t6d3 # hostname1 vgname1
Preffered Output:
Code:
c0t2d0 c0t4d0 # hostname vgname
c0t2d1 c0t4d1 # hostname vgname
c0t2d2 c0t4d2 # hostname vgname
c0t3d0 c0t6d0 # hostname vgname1
c0t3d3 c0t6d3 # hostname vgname1
The only constant variable in this all is the vgname.
I've searched the forum simular posts, but when trying i don't get the desired output. The biggest problem is the formating of the output file.

Can someone help me with this.

Running HP-UX B.11.23 ia64
  #2 (permalink)  
Old 12-01-2008
martva martva is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 4
I have just tried the join command. Not what i need right now.

I have also tried this one:

Code:
cat file1 | awk {'print $2'} > file3
cat file2 | awk {'print $1, $3, $4, $5'} > file4
paste file3 file4
There most be an easier way. Also with this option I have to check every ctd number in every line is are part of the same VG.

Last edited by martva; 12-01-2008 at 11:50 AM..
  #3 (permalink)  
Old 12-01-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool Patience...

Your followup message includes only: "Anyone? "

You did not provide the rules for how to combine the two files into one file.
It appears that you are taking the 2nd column of file one, making it the first column of your output; and taking the 2nd column to end of file two, making it columns two to end of your output.

Correct?
  #4 (permalink)  
Old 12-01-2008
martva martva is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 4
Yes, that's correct.

So in the example above my output will be the following:

c0t2d0 c0t0d0 # hostname1 vgname
c0t2d1 c0t0d1 # hostname1 vgname
c0t2d2 c0t0d2 # hostname1 vgname
c0t3d0 c0t1d0 # hostname1 vgname1
c0t3d3 c0t1d3 # hostname1 vgname1
  #5 (permalink)  
Old 12-01-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Here is an approach using awk

Code:
> cat file87
c0t0d0 c0t2d0 # hostname vgname
c0t0d1 c0t2d1 # hostname vgname
c0t0d2 c0t2d2 # hostname vgname
c0t1d0 c0t3d0 # hostname vgname1
c0t1d3 c0t3d3 # hostname vgname1
> cat file88
c0t0d0 c0t4d0 # hostname1 vgname
c0t0d1 c0t4d1 # hostname1 vgname
c0t0d2 c0t4d2 # hostname1 vgname
c0t1d0 c0t6d0 # hostname1 vgname1
c0t1d3 c0t6d3 # hostname1 vgname1

> cat f87_88
awk ' FILENAME=="file87" { dat[$1]=$2}
      FILENAME=="file88" { 
        if(FNR > 0)
        { print dat[$1]" "$2" "$3" "$4" "$5}
      
      } ' file87 file88
       
> f87_88
c0t2d0 c0t4d0 # hostname1 vgname
c0t2d1 c0t4d1 # hostname1 vgname
c0t2d2 c0t4d2 # hostname1 vgname
c0t3d0 c0t6d0 # hostname1 vgname1
c0t3d3 c0t6d3 # hostname1 vgname1
  #6 (permalink)  
Old 12-02-2008
martva martva is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 4
He, it works.

Oke, say i want the files to be user provided, because not all files have the same name. Like this:

Code:
> f87_88 file87 file88
That means that the option FILENAME== is user provided.

Second, I need to be sure the devices in the file both correspond the same VG. So that if I run the script, I don't have to check the devices afterwards.

Regards

Edit:
My awk experience is very basic.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0