English 中文(简体)
除电子邮件地址外,如何做到“编辑”删除其他一切。
原标题:How do i get "sed" to delete everything else but email address.
  • 时间:2010-12-14 01:48:57
  •  标签:
  • sed

除电子邮件地址外,如何做到“编辑”删除其他一切。

db dump: someusername ::: kRW...0fPc ::: $2a$10$...aucvkDt86 ::: joesmith@gmail.com
最佳回答

是否有必要打耳? gr什么? 这里,请你告诉你:

$ cat dbdump.txt 
db dump: someusername ::: kRW...0fPc ::: $2a$10$...aucvkDt86 ::: joesmith@gmail.com
another line with two e-mail addresses <test@example.com> on it -- bob@example.org

$ grep -EiEio  [A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}  dbdump.txt
joesmith@gmail.com
test@example.com
bob@example.org

<代码>-o只字标出对应部分,即电子邮件地址。 -i使对配对案不敏感。 甚至在同一条线上发现了多个电子邮件地址。

<><>Edit>: 页: 1 页: 1 还将发挥作用......

问题回答

这要求德国国籍<代码><>。

sed -r  s/[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}/
&
/ig;s/(^|
)[^@]*(
|$)/
/g;s/^
|
$//g;/^$/d  inputfile
  • split input lines so email addresses and other strings are separated by newlines
  • erase sequences that consist of only non-@ characters delimited by newlines or the beginning or end of the input line
  • erase extra newlines and blank lines

如果每行有一个电子邮件地址,则以下任何事项都不会发生。 如果不止一次,它只能显示最后一行。 它还赢得了没有有效电子邮件地址的线索。

sed  s/^.* ([^@ ]+@[^ ]+) ?.*$/1/ 

Input

$ cat dbdump
this line with no valid @ email address is untouched
::: a0$...aucvkDt86 ::: joesmith@gmail.com
::: a0$... foo@example.com db dump: someusername :::

Output

$  sed  s/^.* ([^@ ]+@[^ ]+) ?.*$/1/  ./dbdump
this line with no valid @ email address is untouched
joesmith@gmail.com
foo@example.com

<代码>:

$ echo "db dump: someusername ::: kRW...0fPc ::: $2a$10$...aucvkDt86 ::: joesmith@gmail.com"|sed  s/.*::: //  joesmith@gmail.com 

缩略语

$ echo "db dump: someusername ::: kRW...0fPc ::: $2a$10$...aucvkDt86 ::: joesmith@gmail.com"|awk  {print $NF} 

EDIT:鉴于你的评论中的新内容,我们非常难以做你要求做的事情,而没有任何规律。 参看Syntax部分:

标准指出,例如1$%3{C}@example.com是有效的电子邮件地址(如:不)。 您甚至可以引用(本条的例子为<代码>)。 John Doe@example.com。 因此,按照标准,几乎不可能承认有效的电子邮件。

如果你限制你的搜寻,你可以这样说。 1. 初步抽取载有<代码>@的线路:

cat your-file.txt|grep @

然后是上述一些。 你甚至可以做这样的事情:

$ echo "garbage John.Doe123@example.com garbage"|sed  s/[^@]* ([a-zA-Z0-9.]*@[^ ]*).*/1/ 
John.Doe123@example.com

注:以上假设如下:

  • There s a space before an email address
  • There are no spaces in an email address itself
  • There is one email address in the line (it will actually get only the first one, so it can work with more then one)
  • The local-part (all before @) contains only letters (lower- or upper-case), digits and a dot

([a-zA-Z0-9.])





相关问题
how to tell sed "dot match new line"

I can t figure how to tell sed dot match new line: echo -e "one two three" | sed s/one.*two/one/m I expect to get: one three instead I get original: one two three

sed: using search pattern in output

I d like to use the search pattern in the output part of a sed command. For instance, given the following sed command: sed /HOSTNAME=/cHOSTNAME=fred /etc/sysconfig/network I d like to replace the ...

Text manipulation and removal

I have text files generated by one of my tools with structure shown below. 1 line text (space) multiple lines text (space) multiple lines text nr 2 ----------------------------------------------------...

Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

how to use sed, awk, or gawk to print only what is matched?

I see lots of examples and man pages on how to do things like search-and-replace using sed, awk, or gawk. But in my case, I have a regular expression that I want to run against a text file to extract ...

Bulk Insert Code Before </body> Tag in 100 Files

I d like to insert <?php include_once( google_analytics.php ); ?> before the closing body tag of about 100 php files. Unfortunately the person who made the site didn t make a header or ...

Extract float from text line with sed?

I am issuing a sed replace on a line, trying to extract a particular floating-point value, but all that appears to be matched is the right-side of the decimal Text Line: 63.544: [GC 63.544: [DefNew: ...

热门标签