LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-01-2007, 02:16 AM   #1
csdhiman
Member
 
Registered: Mar 2007
Posts: 47

Rep: Reputation: 15
sed query


Dear all

I want to grep all mail ids from /var/maillog file to check who is using mail service

i don't know what will be the syntex for this query in sed command

pls tell me the sed syntex for this
 
Old 10-02-2007, 08:03 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
GREP and SED are two different commands.

To simply find a particular expression in a file, use GREP. If you want to change something, then SED is one of the tools you can use.

For example, to display all lines in filename which contain keyword:
cat filename | grep keyword

For more and better help, post a sample of the file format and the exact output you would like

Good manuals are at http://tldp.org ---I would start with Bash Guide for Beginners
 
Old 10-05-2007, 02:40 AM   #3
csdhiman
Member
 
Registered: Mar 2007
Posts: 47

Original Poster
Rep: Reputation: 15
The maillog file has

cat maillog|more
Oct 1 12:25:37 ns5 popper[11080]: (v3.0.2-mysql-0.10.2) POP login by user "user1
@example.com" at (59.94.251.158) 59.94.251.158
Oct 1 12:25:37 ns5 popper[10997]: I/O Error from at 59.94.211.8 (59.94.211.8):
[-1] 104 (Connection reset by peer); 0 (Success)
Oct 1 12:25:37 ns5 popper[10997]: (null) at 59.94.211.8 (59.94.211.8): -ERR POP
EOF or I/O Error: 104 (Connection reset by peer); 0 (Success)
Oct 1 12:25:37 ns5 popper[11080]: Stats: user2@example.com 0 0 0 0 59.94.25
1.158 59.94.251.158
Oct 1 12:25:38 ns5 popper[11085]: (v3.0.2-mysql-0.10.2) POP login by user "user3@example.com" at (59.94.251.158) 59.94.251.158
Oct 1 12:25:39 ns5 popper[11088]: (v3.0.2-mysql-0.10.2) POP login by user user4@example.com at (90.0.0.70) 90.0.0.70
Oct 1 12:25:39 ns5 popper[11088]: Stats: user5@example.com 0 0 0 0 90.0.0.70

now i want output like this
user1@example.com
user2@example.com
user3@example.com
user4@example.com
user5@example.com

Last edited by csdhiman; 10-05-2007 at 03:08 AM.
 
Old 10-05-2007, 07:18 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
First, this will be easiest if the desired string is always in the same format--eg _"user@example.com"_ (where "_" means space. Let's assume that is the case---here is a crude beginning:

"names" is the filename is used for the test.

cat names | sed -n 's/.*\( ".*@.*\..*" \).*/\1/p'

This uses the "backreference" feature of SED. Everything inside the escaped parentheses-- \(...)\ -- is substituted using \1

So....... It says call sed with no print option (-n), substitute the first occurence of the first expression with the backreference, and print that result.

The first expression reads as follows: "any # of characters, followed by the back-referenced expression, then followed by any number of characters."

In turn, the back-referenced expression is: "a space, then a ", then any # of characters, a @, any # of characters, a ., any #of characters, a ", and a space"

This will make a lot more sense after reading a good tutorial---eg: http://www.grymoire.com/Unix/Sed.html#uh-8

Last edited by pixellany; 10-05-2007 at 07:21 AM.
 
  


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
help with mysql query: return nth rows in query hawarden Programming 2 07-31-2006 06:36 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:09 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