Script to consolidate files as mails,groupid


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to consolidate files as mails,groupid
# 1  
Old 08-30-2010
Script to consolidate files as mails,groupid

Hi, I'm newbie in Bash scripting.
Here is scenario I've a file which containslist of 100 mailgroup and in a directory i have 100 files with each group's respective mail addresses.

I'd like to make one CSV file with this information as follows.

consolidated files with

mailid,groupname.

Please help me to make script for this.

cheers.
# 2  
Old 08-30-2010
too less informations. if you need help, provide some samples input files first.
# 3  
Old 08-31-2010
I've got one group.txt file. In this file there are 120 mailgroups like

hostaff
financedept
accountsdept
itdept
...
...
etc etc

I've extracted mail ids in these groups file names as hostaff.txt contains
abc@example.com
bsd@example.com
sde@example.com
...
...
etc

I', like to fill all group names besides mail ids in one file as follows

abc@example.com,hostaff
bsd@example.com,hostaff
trer@example.com,financedept
sds@example.com,finacedept
srw@example.com,accountsdept
...
...

Please Help me to make a script..

Cheers.
# 4  
Old 08-31-2010
not clear.

Do you mean assign each mailgroup assign to two mailboxes only?
# 5  
Old 08-31-2010
No, if there is a mailids files with 100 mailids than in consolidated file it has to show mailid1,mailgroup
mailid2,mailgroup
mailid3,mailgroup like that

I've tried it with sed like follows

in shell it works perfect like

sed 's/$/,mailgroup/g' mailidsfile > consolidated.txt

but in bash script it does not work. my script is as follows

Code:
#!/bin/sh
file=/home/test/mailgroups.txt
for i in file
do sed 's/$/,$file/g' $file > consolidated.txt
done

it gives error : sed: -e expression #1, char 11: unterminated `s' command


Cheers
# 6  
Old 08-31-2010
Ok, for each mailbox, you need attach all mailgroups on it.

Try this:

Code:
awk 'NR==FNR{a[$1];next}{for (i in a) print $0 "," i}' group.txt mail_ids.txt

abc@example.com,accountsdept
abc@example.com,hostaff
abc@example.com,financedept
abc@example.com,itdept
bsd@example.com,accountsdept
bsd@example.com,hostaff
bsd@example.com,financedept
bsd@example.com,itdept
sde@example.com ,accountsdept
sde@example.com ,hostaff
sde@example.com ,financedept
sde@example.com ,itdept

# 7  
Old 08-31-2010
Thanks for your help
It has not completed my requirement.

Let me explain in detail.

I've a folder which has 100 mail ids files under groupnames.

Ex:

accountdept.txt file contains 100 mailbox list

abc@example.com
bcd@example.com
sds@example.com

hostaff.txt contains 500 mailbox list
financedept.txt contains 30 mailbox list

There are 100 group files in a folder each contains 50-500 mail ids

I want to export all the information in a single file with either mailid,mailgroup format
OR each mailgroup header with mailids under that list

Please help me how to get that.

Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate E-Mails with content on different files

Hello, I am using a script to create a random password for a user. The file looks like user1:thepassword1 user2:thepassword2 user3:thepassword3 Passwords are openssl passwd hashed. I have an own file where the password is written in cleartext. Now i want to send an E-Mail to the... (8 Replies)
Discussion started by: Manu_H
8 Replies

2. Shell Programming and Scripting

[Help] Bash script that runs in the background and checks for mails...

Hello! I have got a homework. The bash script runs in the background and checks the user's mailbox and when the user gets a new mail a popup window appears with some text and information about the sender (from who and when).I have no idea how to start, any help would be appreciated! Thank you:) (1 Reply)
Discussion started by: capo2ndfret
1 Replies

3. Shell Programming and Scripting

Help with consolidating mails sent by executing script

I have a script which checks for swap usage of the unix server. A cron job has been created to execute this script every hour and send the output via mail. This output is only required for a particular duration and it can range anywhere from 6 hours to 10 hours. So we are commenting out the... (1 Reply)
Discussion started by: kiran1112
1 Replies

4. Shell Programming and Scripting

Consolidate files based on priority

please help, I would like to merge 4 files, all of them same format. The first col is the key for all files,followed by variable number of fields so I want to check if the key is present in the files according to priority and then also add a column saying it came from which file . So the... (4 Replies)
Discussion started by: ritakadm
4 Replies

5. Shell Programming and Scripting

Mails from shell script

Hello Gurus, I am facing some issues while doing the automation of some progs. The requirement is if any prog fails with error automatically the script will send alert for such failed progs. Below is the table structure:- PROG_NAME Description... (1 Reply)
Discussion started by: pokhraj_d
1 Replies

6. Shell Programming and Scripting

Script for count files and send mails

Hi. I'm new on this forum and I need if possible someone to help me with one script. The script should act like this: - should be run by crontab and have next parameters: script_name $par1 $par2 $par3 $par4 where script will search in dir $par1 for files with mask $par2 and if number of... (2 Replies)
Discussion started by: atrailm
2 Replies

7. UNIX for Advanced & Expert Users

Sendmail Script don't deliver mails

Hi, i've got a problem with a sendmail script, which sends HTML mails. Some mail will rejected by the mail server, because the fqdn doesn't exist. Where can i set the sender-domainname by sendmail? My mail server say: "Sender address rejected: Domain not found;", which is correct... (3 Replies)
Discussion started by: rainbowwarrior
3 Replies

8. UNIX for Advanced & Expert Users

shell script to send separate mails to different users from a text file

Hi Friends, Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file. text file contains the no. of records like: Code: giridhar 224285 847333 giridhar276@gmail.com ramana 84849 33884... (0 Replies)
Discussion started by: giridhar276
0 Replies

9. Solaris

How to add auserid and groupid in vxvm?

how to add auserid and groupid in vxvm? (6 Replies)
Discussion started by: rahulpakanati
6 Replies

10. UNIX for Dummies Questions & Answers

Script to delete mails from maildir

Hi buddies, Anybody has any script to delete mails from Maildir/cur??? I mean is it possible to delete mails from Maildir/cur matching a particular subject like spam or fax??? Thanks in advance (1 Reply)
Discussion started by: squid04
1 Replies
Login or Register to Ask a Question