use script to create a data file of mulitple users
How do I write a script that read a line from a file and recreate mulitple lines in another file? for example, I have one line information about a user, the prefix user name is 'test', user's email address is 'test@abc.xyz.com', the alias is 'test' etc. I want to populate this data into the following,
test1 test1@abc.xyz.com test1 test2 test2@abc.xyz.com test2 test3 test3@abc.xyz.com test3 : test5000 test5000@abc.xyz.com test5000 In other word, the script needs to read the first token (user name prefix) from the first file and create mulitple users by appending the counts and replace the email address from the first time with the new user name and the alias. The script will accept the command line parameter for the max number of users like "createuser.sh 5000" will create 5000 users, 1 line per user. Any help is appreciate. |
This is either mondo sysadmin stuff or homework. Assuming the former, this is kinda crappy, but
Code:
user="$(awk '{ print $1 }' file)" Code:
user="$(awk '/'$1'/{ print $1 }' file)" I'm sure there's a better way, but that's the first thing that came to mind. |
something like:
Code:
#!/bin/bash |
thanks, for the code you provided below, where I specify the first file?
user="$(awk '/'$1'/{ print $1 }' file)" >file2 for (( i=1; i<=$2; i++)); do sed "s/$user/$user$i/g" file >> file2 done |
The first $1 is bash expecting the user name you want, like 'test'. The second $1 is awk grabbing the first field. The $2 is the number argument, like '5000'. So it'd be 'createuser.sh test 5000'. I thought the file names were supposed to be 'hard coded'. If you wanted to provide the file names as command line arguments, just substitute 'file' (input) and/or 'file2' (output) with $3 and $4 throughout. 'Course, then you're getting into the ballpark of maybe wanting to use getopts and letter options, rather than trying to remember the order of everything.
|
All times are GMT -5. The time now is 02:35 PM. |