extract columns from file and send mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract columns from file and send mail
# 1  
Old 04-15-2011
extract columns from file and send mail

Hi
I have a file of the form

Code:
name1,lastname1,email1@gmail.com,9.08243E+12,team1,role1,username1,password1
name2,lastname2,email2@gmail.com,9.08243E+11,team2,role2,username2,password2

I need to extract the email (column 3) and send a mail to each person, with their details ( specifically username and password.). so for eg 100 emails for 100 lines

I think this should be possible using awk and mailx but I am not able to get it to work

Any help would be appreciated.
Thanks
# 2  
Old 04-15-2011
If you know, that email is always third, and username and password are always second to- and last ones, then this is a simple approach:
Code:
 awk -F, '{print "echo Your username is " $(NF-1) " and your password is " $NF " | mail -s mail_subject " $3}' file | sh

If you omit the last pipe '| sh', you can test the output (print it on screen). To execute, pipe it to sh.
This User Gave Thanks to mirni For This Post:
# 3  
Old 04-15-2011
Hi mirni
How the the | sh work? would be glad if you could point me to some documentation
thanks
# 4  
Old 04-15-2011
'sh' is shell (usually /bin/sh, which is usually a symbolic link to bash, dash, ksh or other shell).
So by piping a command to shell, it gets executed. Simple like that.

E.g.:
Code:
$ echo cat /etc/passwd
cat /etc/passwd

Code:
$ echo cat /etc/passwd | sh   #same as invoking 'cat /etc/passwd' directly
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
....

It is the same as calling the argument of echo in command line; that echoing makes debugging easy though, and will echo the command to the stdout before you are ready to execute it
This User Gave Thanks to mirni For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies

2. Shell Programming and Scripting

Match Columns in one file and extract columns from another file

Kindly help merging information from two files with the following data structure. I want to match for the CHR-SNP in Foo and get the columns that match from CHROM-rsID Fields 1 & 2 of foo may have duplicates, however, a joint key of Fields $1$2$3$4 is unique. Also would be helpful to clean up... (4 Replies)
Discussion started by: genehunter
4 Replies

3. Programming

How to send a file in e-mail from on Linux C++?

Hi ! I-m copile from source a C++ program from tutorials from internet. I don't understendig any programing languages.. but compiled aplication running ok. I-ts possible to add in my used program, lines to send one file from config directory in e-mail, to my e-mail adress ? I want to run... (2 Replies)
Discussion started by: kraftwerk
2 Replies

4. Solaris

Send file attachement in mail

Hello, I am able to attache the file in UNIX/LINUX script using following code. MAILFORMAT="Please do not replay this mail.This mail is auto generated." echo -e $MAILFORMAT | mailx -r autoreplay@gmail.com -a filename -s "status" xyz@gmail.com But same I am not able attache... (6 Replies)
Discussion started by: nes
6 Replies

5. UNIX for Dummies Questions & Answers

Converting txt output to rows and columns and send report via mail.

Hi All, I would like to send below output in a tabular column ( xml or excel ) and send a mail. vinay unix anil sql vamsee java request to suggest a solution. (1 Reply)
Discussion started by: Girish19
1 Replies

6. Shell Programming and Scripting

To send mail with same format as in file

I want to send the content in same format as it is in file. #!/bin/sh cat /usr/test/abc > /usr/test/abc/file if then MAILTO=test@yahoo.com CONTENT="/usr/test/abc/file" ( echo "Subject: TEST " echo "MIME-Version: 1.0" echo "Content-Type: text/html" cat $CONTENT ) |... (7 Replies)
Discussion started by: rajjev_saini123
7 Replies

7. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

8. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

9. UNIX for Dummies Questions & Answers

How to send file in mail

Hi I want to send out a file that generate 1st of each month that have formate like this 11012008_experience_rate_log.txt Now I have setup a cronjob that usually sent this file in mail like cat /data02/transfer/*_experience_rate_log.txt | mail -s 'PICS EXP RATE Logs' lger@bd.com So how... (3 Replies)
Discussion started by: vishalpatel03
3 Replies

10. Shell Programming and Scripting

Pull E-mail address from file, send e-mail

Hello, I am new to perl and need to create a script that will read a file and pull a name from the file and send e-mail. How can I use the following awk statement in a perl script? grep UNIXadmins /root/mail.conf | awk '{ print $2}' and use the output to send a e-mail. Any help would... (1 Reply)
Discussion started by: DC Heard
1 Replies
Login or Register to Ask a Question