Generate unique user id with each addition of data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generate unique user id with each addition of data
# 1  
Old 11-29-2011
Generate unique user id with each addition of data

As I add new data to database.txt I want to generate a unqiue User Id. This is my current solution.

Code:
echo $RANDOM:$lname:$fname >> database.txt

But I seem to have problems when I try and use $RANDOM for formatting like so:

Code:
grep "^4539" database.txt | awk -F":" '{print "User ID:\t"$RANDOM"\nLast Name:\t" $lname"\nFirst Name:\t"$fname}'

How can I generate a unique user id another way. Where the variable can be used for piping and formatting?
# 2  
Old 11-29-2011
* How long can this unique user id be?
* In one of my scripts, I had used the following to generate a unique string. See if this helps:
Code:
USER_ID="user`date +%Y%m%d%H%M%S`"

Of course, if you were to use the variable USER_ID more than once within a second, then this would fail.
# 3  
Old 11-29-2011
Sounds good. Calling that variable would simply require a $USER_ID correct?
# 4  
Old 11-29-2011
Try
Code:
grep "^4539" database.txt | awk -F":" -vRAND=$RANDOM '{print "User ID:\t"RAND"\nLast Name:\t" $lname"\nFirst Name:\t"$fname}'

# 5  
Old 11-29-2011
If you want to use any variables inside awk, you will need to pass them...
Try this to get the usage...
Code:
awk -v arg=$RANDOM 'BEGIN{print arg}'

Also, use of grep is not required when you can achieve the same with awk!
Code:
awk '/^4539/{...}' input_file

HTH
--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

Generate 10000 unique audio file of 2MB each using shell script.

Hi, I want 10000+ unique Audio file of approx 2MB each. How can i generate numerous audio files using shell script. Any tool, command or suggestions are welcome. If i give one audio seed file then can we create numerous unique files with same seed file? Any help is highly appreciable.... (11 Replies)
Discussion started by: sushil.kumar
11 Replies

3. Shell Programming and Scripting

Generate unique mac address

Hi, I want to generate 2000 mac address. Please let me know how to do so. Perl script or there is some tool availlable wherein i can give the count and it will generate that many mac-address Thanks, Kriti (4 Replies)
Discussion started by: kriti
4 Replies

4. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

5. Shell Programming and Scripting

Help with figuring division and addition based on column data and line numbers

I have a data file in the format of 1234 xxx 1234 xxx 1234 xxx 1234 xxxI want to be able to calculate the following - COLUMN1+((LINENUMBER-1)/365) The output needs to preserve the 2nd column - 1234 xxx 1234.00274 xxx 1234.00548 xxx What is the best way to do this? I am somewhat... (9 Replies)
Discussion started by: ncwxpanther
9 Replies

6. Shell Programming and Scripting

How to generate 10.000 unique numbers?

hello, does anybody can give me a hint on how to generate a lot of numbers which are not identically via scripting etc? (7 Replies)
Discussion started by: xrays
7 Replies

7. Shell Programming and Scripting

User addition in Unix box

Hi All, Am using the following command to add a user in Unix box useradd -d <default_path> -g 90 -p <pwd for the user> <user_name> But am getting an error while using this command by root user.Let me know if this cmd is right or else is there any other command to add a user in unix... (9 Replies)
Discussion started by: Ashok_oct22
9 Replies

8. Shell Programming and Scripting

need to generate unique id from constant sid

Hello I have multiple accounts that running application that uses unique port number I want to generate this port from some sid number that stays constant for every user account , is there any place in the system that generate number that is unique to the account ? thanks (0 Replies)
Discussion started by: umen
0 Replies
Login or Register to Ask a Question