How can i prepare grant staement with 2 files ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can i prepare grant staement with 2 files ?
# 1  
Old 06-22-2016
How can i prepare grant staement with 2 files ?

---file1 ( tables
Code:
A
B
C
D
E
F
...
...
Z

---file2
Code:
Joe
Bob
Mary
Sally
Fred
Elmer
David


All i want is


Code:
grant select on TABLE A to user Joe
grant select on TABLE B to user Joe
grant select on TABLE C to user Joe 
grant select on TABLE D to user Joe 
grant select on TABLE E to user Joe
....
grant select on TABLE Z to user Joe

Code:
grant select on TABLE A to user Bob
grant select on TABLE B to user Bob
grant select on TABLE C to user Bob
grant select on TABLE D to user Bob
....
grant select on TABLE Z to user Bob



It has to go till number users given in file 2 ....Can some one help ?
# 2  
Old 06-22-2016
The following seems to do what you want pretty simply:
Code:
awk '
FNR == NR {
	t[nt = NR] = $0
	next
}
{	for(i = 1; i <= nt; i++)
		print "grant select on TABLE", t[i], "to user", $0
}' file1 file2

producing the output (greatly abbreviated):
Code:
grant select on TABLE A to user Joe
grant select on TABLE B to user Joe
grant select on TABLE C to user Joe
grant select on TABLE D to user Joe
grant select on TABLE E to user Joe
grant select on TABLE F to user Joe
grant select on TABLE ... to user Joe
grant select on TABLE ... to user Joe
grant select on TABLE Z to user Joe
grant select on TABLE A to user Bob
... abbreviated ...
grant select on TABLE Z to user Elmer
grant select on TABLE A to user David
grant select on TABLE B to user David
grant select on TABLE C to user David
grant select on TABLE D to user David
grant select on TABLE E to user David
grant select on TABLE F to user David
grant select on TABLE ... to user David
grant select on TABLE ... to user David
grant select on TABLE Z to user David

with the sample input files you provided.

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to prepare a CSV table with inputs from multiple files

Hi, We have thousands of Video files and we need to prepare a table with few of it's parameters/values from their Mediainfo output. Here I have 3 sample mediainfo output text files named Vid1, Vid2 & Vid3 so on... (such we have thousands) and each file has exactly 3 lines. $ ls... (6 Replies)
Discussion started by: prvnrk
6 Replies

2. Shell Programming and Scripting

How to grep the grant statement and output to the different files?

Hi currently I have a list of *.sql files. one of the file, terminal is Prompt Table TERMINAL; CREATE TABLE TERMINAL ( TERMINAL_ID NUMBER(8), EXCEL_TERMINAL_ID NUMBER(8), MERCHANT_ID NUMBER(8), SETTLE_TIME VARCHAR2(4 CHAR) ); COMMENT... (4 Replies)
Discussion started by: jediwannabe
4 Replies

3. UNIX for Advanced & Expert Users

find -exec with 2 commands doesn't work (error incomplete staement)

Hi Gurues, I need to modify an existing script that uses find to search a folder, and then move its contents to a folder. What I need to do is run gzip on each file after it's moved. So, I ran this little test: Put a ls.tar file on my $HOME, mkdir tmp, and then: virtuo@tnpmprd01: find .... (3 Replies)
Discussion started by: llagos
3 Replies

4. UNIX for Dummies Questions & Answers

grant sudo permission

Hi all, I have to grant sudo permission to a user. I have searched online and find that /etc/sudoers file needs to be changed with visudo command. As i am new to linux, this is not clear to me. Can anybody take an example and show me how exactly this done. Thanks in advance! (2 Replies)
Discussion started by: lramsb4u
2 Replies

5. Solaris

Grant print related privileges

Afternoon everyone, I would want to ask that how/what privileges i should grant to a new user so that the user can clear /disable printing job queue? Solaris OS: 5.9 Thanks. :b: (4 Replies)
Discussion started by: beginningDBA
4 Replies

6. Programming

Grant privileges in Oracle

i have installed oracle 10g and two databases. i enter database1 as sysdba and create a user called user1.i give the privileges as "select on" to user1. i enter sqlplus from the shell prompt. i enter as user1. but when i do "select * from emp" i have a "the table doesn't exist". how can i give... (3 Replies)
Discussion started by: symeje
3 Replies

7. Shell Programming and Scripting

How can i prepare a file by comparing two other files?

File 1 data: TestA TestB TestC File 2 data: TestA TestD TestE My Output File (pick all from both and create a file without duplicate data) ---------------------------------------------------------------------- TestA TestB TestC (3 Replies)
Discussion started by: manmohanpv
3 Replies

8. UNIX for Dummies Questions & Answers

MySQL GRANT permission.

Hi, I'm one of a server administrators. I've the linux root account but I don't know the root password of MySQL (Server version: 5.0.32). I want to GRANT ALL PRIVILEGES to my MySQL account without changing the MySQL's root password. How can I do so? (0 Replies)
Discussion started by: mjdousti
0 Replies
Login or Register to Ask a Question