![]() |
|
|
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 |
| nim master | manoj.solaris | AIX | 0 | 04-22-2008 03:43 PM |
| Append filename to datafile | Satyagiri | UNIX for Dummies Questions & Answers | 3 | 10-12-2006 10:19 AM |
| selective positions from a datafile | ganapati | Shell Programming and Scripting | 10 | 09-19-2006 10:09 AM |
| oracle datafile *dbf | tt155 | SUN Solaris | 3 | 12-17-2005 07:38 PM |
| replace one section in a datafile | Paprika | Shell Programming and Scripting | 4 | 06-17-2005 09:48 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Combine a datafile with Master datafile, emergent!
Hi guys, my supervisor has asked me to solve the problem in 7 days, I've taken 3 days to think about it but couldn't figure out any idea.
Please give me some thoughts with the following problem, I have index.database that has only index date: 1994 1995 1996 1997 1998 1999 I have small.database.csv that contains data for some of the indexed dates but not all of them: 1995, california, A3,B6 1999, vermont, A4,B9 I want to match the small.database.csv into index.database into a combined.database.csv so it would look like: 1994,,, 1995, california, A3,B6 1996,,, 1997,,, 1998,,, 1999, vermont, A4,B9 shell scripts or perl would both be fine Thanks a lot. My supervisor is after me on this one. |
|
||||
|
If you can use Python, here's an alternative: Code:
#!/usr/bin/python
flag=0
for line in open("file1"):
line = line.strip()
for line2 in open("file2"):
if line2.split(",")[0] == line:
print line2.strip()
flag=1
if flag:
flag = 0
continue
else: print "%s,,," % line
output: Code:
# ./test.py 1994,,, 1995, california, A3,B6 1996,,, 1997,,, 1998,,, 1999, vermont, A4,B9 |
|
||||
|
Quote:
Code:
#! /opt/third-party/bin/perl
open(FILE, "<", "small") || die "Unable to open file small <$!>\n";
while(<FILE>) {
chomp;
$fileHash{$_} = $i++;
}
close(FILE);
open(FILE, "<", "index") || die "Unable to open file index <$!>\n";
while(<FILE>) {
chomp;
$set = 0;
foreach my $v ( sort keys %fileHash ) {
if ( $v =~ m/^$_/ ) {
print $v . "\n";
$set = 1;
last;
}
}
print "$_,,,\n" if ( $set == 0 );
}
close(FILE);
exit 0
This should be fast ! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|