![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 Code:
c0t0d0 c0t4d0 # hostname1 vgname c0t0d1 c0t4d1 # hostname1 vgname c0t0d2 c0t4d2 # hostname1 vgname c0t1d0 c0t6d0 # hostname1 vgname1 c0t1d3 c0t6d3 # hostname1 vgname1 Code:
c0t2d0 c0t4d0 # hostname vgname c0t2d1 c0t4d1 # hostname vgname c0t2d2 c0t4d2 # hostname vgname c0t3d0 c0t6d0 # hostname vgname1 c0t3d3 c0t6d3 # hostname vgname1 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 |
|
||||
|
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
Last edited by martva; 12-01-2008 at 11:50 AM.. |
|
||||
|
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 |
|
|||||
|
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
|
|
||||
|
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 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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|