update base


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting update base
# 1  
Old 05-29-2008
update base

hello everyone
I need to update data base in file

1-ID
2-Name
3-ID group
4-ID teacher
5-mark list

unique ID is (ID+ID group+ID teacher)
we can append 5 th columns (marks list)

main base file:
Code:
1:John:3:1:4 3 2
2:Mark:1:2:1 3
3:Susan:3:4:

input file:
Code:
2:Mark:1:2:1 3 5 6
3:Susan:3:4:2 4 3

main base file after update:
Code:
1:John:3:1:4 3 2
2:Mark:1:2:1 3 5 6
3:Susan:3:4:2 4 3

# 2  
Old 05-29-2008
What have you tried so far and where exactly are you stuck?
# 3  
Old 05-29-2008
I try put both files to array and after that compare by student ID+teacher ID+class ID. But I do not no its good idea. And I do not now how to print it proper.
# 4  
Old 05-29-2008
Quote:
Originally Posted by mleplawy
I try put both files to array and after that compare by student ID+teacher ID+class ID. But I do not no its good idea. And I do not now how to print it proper.
actually it's the approach I'd take.
How exactly have you tried to accomplish this?
Show the code, pls.
# 5  
Old 05-29-2008
I have a problem with add files to array and with compare student ID
Code:
awk 'BEGIN {x=0}{z=0}{y=0}

{getline base[x++] < "base" }

{getline input[z++] < "input" }
 
END
{for (i in base)
    for(n in input)
	if (base[i]==input[n]) //I now, it's not OK column 1,3,4 must be ==
	    output[y++]=input[n]
	else
	    output[y++]=base[i]
}	

{for (z in output)
print output[z] > "base"}'

# 6  
Old 06-02-2008
could anyone hlep me with that? pls
# 7  
Old 06-02-2008
I am only able to get the following .

Code:
$ cat input.txt
2:Mark:1:2:1 3 5 6
3:Susan:3:4:2 4 3


$ cat main.txt
1:John:3:1:4 3 2
2:Mark:1:2:1 3
3:Susan:3:4:


$ awk '
BEGIN {FS=":"}
NR==FNR{arr[$1]=$0;next}
$1 in arr && $0=arr[$1]
 ' input.txt main.txt
2:Mark:1:2:1 3 5 6
3:Susan:3:4:2 4 3

//Jadu
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Red Hat

RedHat 5 update 9 BASH update issue

Hi i want to update the BASH because of the "shell shock" vulnerability. my RedHat 5 is clean install with the default mirror site. when im running the command: yum update bash im getting a message saying there is no update. you can see in the attach picture... what am i doing wrong? is... (4 Replies)
Discussion started by: guy3145
4 Replies

2. Programming

MYSQL - trigger update on record insert or update

Right I have a MYSQL database with table1 with 3 columns, colA, colB and colC. I want to combine the data in the 3 columns into a 4th column names col_comb. Here's the SQL command that works: UPDATE table1 SET `col_comb` = CONCAT( `colA` , ' - ', `colB` , ', ', `colC` ); So now I want this... (5 Replies)
Discussion started by: barrydocks
5 Replies

3. Red Hat

CentOS 6.1 base install (like FreeBSD base install)?

Hello, What is the simplest way to install CentOS 6.1 with console base-system only using official LiveDVD image on VirtualBox machine? I'd like to get simplest console with network support like FreeBSD base installation. Then, install services which I need. The installer jest extracts the... (2 Replies)
Discussion started by: newbie_develope
2 Replies

4. Shell Programming and Scripting

using base name with awk

:wall: find . -type f -exec ls -l {} \; | awk '$5 $9 {print $5 $9}' I would like $9 to be without path information, but simply the file name. Thanks for any consideration. (5 Replies)
Discussion started by: robin_simple
5 Replies

5. AIX

Problem with the ODM base

Hi, I gonna try to explain my problem. When I list my tty I have something like that: sa3 is the RAN where the tty are connected. Yesterday I tried to delete every tty from the RAN I had a problem with a tty which was not possible to delete with rmdev -dl, so I had to : - delete it... (0 Replies)
Discussion started by: Castelior
0 Replies

6. Shell Programming and Scripting

data base update

hello everyone I need to update data base in file 1-ID 2-Name 3-ID group 4-ID teacher 5-mark list unique ID is (ID+ID group+ID teacher) we can append 5 th columns (marks list) main base file: Code: 1:John:3:1:4 3 2 2:Mark:1:2:1 3 3:Susan:3:4: input file: (1 Reply)
Discussion started by: mleplawy
1 Replies

7. Programming

what is the base type of enum

helo i have asked in exam what that what is the base type of enum options are given bewlo (1) long int (2) short int (3) signed int (4) unsigned int can u tell me what is the exact answer from the above option Regards, Amit (1 Reply)
Discussion started by: amitpansuria
1 Replies

8. Programming

data base

Dear sirs, I am new to DataBase in C++,Also here iam using mysql, How can do it nad get the result back from the database and do operation onit. Thanks in advance, arunkumar (2 Replies)
Discussion started by: arunkumar_mca
2 Replies
Login or Register to Ask a Question