LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-09-2009, 10:00 PM   #1
mitchell2345
Member
 
Registered: Aug 2008
Posts: 55

Rep: Reputation: 16
Using sed or awk to filter a file


Hi,

I am using Mailman to create a mailing list for my company. Our membership database is stored in a MS SQL 2000 server. I have figuired out how to write a batch script to export my email address into a text file.

The file is formatted as so:
Code:
1> 2> 1> 2> 3> 4> 5> 6> 7> 8> 9>  email@dom.ain                           

 email@dom.ain

.... (many more email address, one every other line.)

 email@dom.ain

 email@dom.ain

(22529 rows affected)
1>
Mailman sync_members scripts needs only email address. How can i use sed and/or awk to filter this file and leave me with just the addresses.

i need a file with each email address, 1 per line. Blank lines are ok.

Thanks,
Mitchell

Last edited by mitchell2345; 04-10-2009 at 09:50 AM.
 
Old 04-10-2009, 12:10 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
for rec in `cat t1.t`
do
    if [[ "$rec" =~ @ ]]
    then
        echo $rec
    fi
done
where t1.t contains your stuff above ....
 
Old 04-10-2009, 09:50 AM   #3
mitchell2345
Member
 
Registered: Aug 2008
Posts: 55

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by chrism01 View Post
Code:
for rec in `cat t1.t`
do
    if [[ "$rec" =~ @ ]]
    then
        echo $rec
    fi
done
where t1.t contains your stuff above ....
Thanks for the reply. I cant seem to get this to work.

here is my simple bash script.

#input file
ifile=/mnt/sql/ome_output.txt

#output file
ofile=/scripts/ome_work.txt

Code:
#pull only emails out of input
for rec in $ifile
do
    if [[ "$rec" =~ @ ]]
    then
        echo $rec >> $ofile
    fi
done
I dont get anything in ome_work.txt when it runs. What am i missing?

thanks,
Mitchell

edit...
NVM! i took out the cat of `cat t1.t` durr.... added that back in and bingo. Thanks

Last edited by mitchell2345; 04-10-2009 at 09:53 AM.
 
Old 04-10-2009, 10:07 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
# awk '{for(i=1;i<=NF;i++){if ($(i) ~ /@/) print $i}}' file
email@dom.ain
email@dom.ain
email@dom.ain
email@dom.ain
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can not capture no at end of file store it and print it using sed and awk amuthiga Programming 10 11-26-2008 07:37 AM
Manipulating Text File with awk or sed kushalkoolwal Programming 2 09-10-2008 07:35 PM
mass file renaming sed/awk/mv asalford Linux - General 2 01-16-2008 05:53 PM
How exclude | from txt.file using awk or sed? sarajevo Programming 2 08-21-2006 07:26 AM
Help with a script to edit text file (awk? sed?) rickh Linux - Newbie 8 04-21-2005 08:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration