Hi Folks,
In my program, I have a variable which consists of multiple lines. i need to use each line as an input. My intention is to extract the email address of the user in each line and use it to process further.
The email address could be anywhere in the whole line. But there will be only one and I need to extract it. The most complex possible format of the email ID is: first-name.last-name@xyz.com
In other words, first and last names are separated by a period (.) and the first and last names may have a hyphen (-). The domain name (@xyz.com) is fixed and only has letters, no numbers.
We have a Solaris OS and I am using Korn shell. I read some examples on SED command and have made a few attempts to use it. But every time, no matter what regex I use, I get the entire input as the output. I must be doing something very basic thing wrong. Could you please suggest?
Note that below is the regex that I arrived at to extract the email address.
Any help is greatly appreciated.
Just feel free to adjust with some additionnal [A-Z] range or whatever but here is an idea :
(The trick is to add a space at the beginning of a line so that if the line contains only the mail address, the next regular expression used to reach the mail adresse preceeded by a space would also match.)
(Just remember that if you want the hyphen to be taken as litteral in a list it should be set at the end of it
quick example : [:#@-]
also consider :
but this would also match an adress with empty user and/or domain like : @.com
so you want it to be at least one char (and you don't want it to be a an hyphen or a dot you can for example:
Just adjust it to your requirements
If you know that the mail address always appear at the end of line and after a space you can simply :
---------- Post updated at 08:25 PM ---------- Previous update was at 07:55 PM ----------
(Ok i didn't handle the case where the separator is a tabulation instead of a space but it's easy to tweak the code or to tr -s '[:blank:]' ' ' <output before applying the sed statement
I would be inclined to prefer [^ \t@] to \w for the bit before the @, since a surprising range of character are allowed in the local part of email addresses: Email address - Wikipedia, the free encyclopedia
This User Gave Thanks to Scrutinizer For This Post:
I am trying to add word in last of particular line.
the same command syntex is running on prompt. but in bash script give error."sed: -e expression #1, char 20: unterminated address regex"
Please help.
for i in `cat servername`;
do
ssh -q -t root@$i sed -i '/simple_allow_groups =/s/$/,... (4 Replies)
I am trying to grep for a particular text (Do action on cell BL330) in a text file(sample.gz) which is searched in the content filtered by date+timestamp (2016-09-14 01:09:56,796 to 2016-09-15 04:10:29,719) on a remote machine and finally write the output into a output file on a local machine.
... (23 Replies)
Discussion started by: rbadveti
23 Replies
3. Forum Support Area for Unregistered Users & Account Problems
I tried to re-register using my new email address which is
<firstname>@<surname>.me
But it never sent out the email confirmation. I had to hit the back button and use my gmail address instead and it came through instantly.
Is there a problem with using .me addresses? (1 Reply)
in Solaris 10 I am able to run:
find . -type f -name "copy*" exec grep example.com {} \;
and I get results.
but when I try to find and sed:
find . -type f -name "copy*" exec sed -e 's/user@example\.com/user2@example\.com' {} \;
the command executes correctly but doesn't change... (6 Replies)
Hi
Input:
aa-bb-cc-dd.ee.ff.gg
Output:
dd
I want to get the word after the last '-' until the first dot
I have tried with regex lookbehind and lookahead like this:
(?<=-).*(?=\.)
but his returns too much
bb-cc-dd.ee.ff (7 Replies)
I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly:
if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Hi All,
I am trying to use a sed command in a shell script in order to delete some lines in a file and I got the following error message.
I don't understand why it is not working 'cause I have tried with simple quotes, then with double-quotes, and it is not working.
sed: -e expression #1,... (7 Replies)
What do you think of this regex to match IP address? I have been reading up on regex and have seen some really long ones for IP. Would this fail in any scenarios?
(+\.){3}* (5 Replies)
Hi All,
How do I send an email using malix where email address contains a #.
I have a email address like this : #test@test.com
I want to send email like malix -s "TEST" #test@test.com < SOMEFILE
I tried \# but doesn't work. Please let me know how we can achieve this?
I am in... (1 Reply)