Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging multiple files into one

Status
Not open for further replies.

octar

Technical User
Oct 21, 2002
28
0
0
AU
Hi, I have around 300 files that I want to get merged into one file, their format is as follows:

file1:
DATE SERVERA
20041101 12
20041102 224
20041103 355
20041104 687
20041105 987

file2:
DATE SERVERB
20041101 3
20041102 6
20041103 66
20041104 567
20041105 4445

file3:
DATE SERVERC
20041101 1
20041102 3
20041103 6
20041104 17
20041105 45

etc....

The output I want is as follows:

DATE SERVERA SERVERB SERVERC ....
20041101 12 3 1 ....
20041102 224 6 3 ....
20041103 355 66 6 ....
20041104 687 567 17 ....
20041105 987 4445 45 ....

All in the one file

note: this is so I can import into excel

Can anyone help???
 
Hi,
It is easier if you use commas "," to separate the fields and call the file

combined.csv

EXCEL can open this file directly without conversion.

This solution assumes that every date appears in every file.

paste file1 file2 file3 | awk '{printf ("%d,%d,%d,%d\n",$1,$2,$4,$6);}' > combined.csv

after the PASTE each line will look like....

DATE SERVERA DATE SERVERB DATE SERVERC
20041101 12 20041101 3 20041101 1
.
.
.

the awk prints columns 1, 2, 4 and 6

DATE SERVERA SERVERB SERVERC
20041101 12 3 1
.
.
.
 
Something like this ?
out=output.csv; rm -f $out
for f in file*; do
[ -f $out ] && join $out $f >$out.1 && mv $out.1 $out || cat $f >$out
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top