Secondly, those are different commands. The grep will match the word "example" followed by any character followed by "com". The sed regular expression will only match "user@example" followed by a dot followed by "com".
How would one go about searching for files named "example*" in a particular directory and then
looking in those files for a string "user@example.com" and replace that string with "user2@example.com"?
This might do what you are looking for:
If there are LOTS of files, the "cat list.txt" will overload the command line buffer. The above syntax should work unless LOTS of files. I don't remember the alternate syntax.
---------- Post updated at 11:16 PM ---------- Previous update was at 11:15 PM ----------
Oh, of course, if no -i option for your sed, redirect output to temp file and mv temp file to replace original file.
Use perl!
And, if looks okay, change to exec perl -i -pe ...
NB: in perl you always need the \@ escape.
A loop has some pitfalls:
NB: quote variables in arguments, do overwrite not (re)create files.
Some shells allow the even safer read -r ...
Last edited by MadeInGermany; 03-12-2013 at 08:18 AM..
How would one go about searching for files named "example*" in a particular directory and then
looking in those files for a string "user@example.com" and replace that string with "user2@example.com"?
Well, if it's just one directory, you don't need find, as suggested by others. A for-loop and file globbing should suffice. For the editing task, ed will do nicely.
If you are familiar with the nuances of the here-document, you may prefer this more readable version:
Note that no other characters (invisible or not) may occur on the line where "EOED" terminates the here-document, except leading tabs (not spaces).
Regards,
Alister
---------- Post updated at 12:14 PM ---------- Previous update was at 11:57 AM ----------
Quote:
Originally Posted by MadeInGermany
A loop has some pitfalls:
Some shells allow the even safer read -r ...
Quote:
Originally Posted by jlliagre
Here is one way to do it with the standard Solaris tools and avoiding the loop issues:
There shouldn't be any pitfalls looping with a POSIX-compliant sh:
Both IFS= and -r are necessary to read text verbatim. The former prevents leading and trailing whitespace from being discarded; the latter disables backslash escaping.
The only limitation that remains is the inability to read a filename with an embedded newline. In my opinion, such a filename is pathological and should be rejected with extreme prejudice.
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)
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... (5 Replies)
Hi there
I lost connectivity to one of our remote systems and when I checked the messages log I found the following:
Aug 10 23:42:34 host xntpd: time reset (step) 1.681729 s
Aug 16 13:20:51 host ip: WARNING: node "mac address" is using our IP address x.x.x.x on aggr1
Aug 16 13:20:51 host... (9 Replies)
Hi,
I'm looking to combine the two commands find and sed together for the work that i'm worknig on.
I need to find the ip addresse in any file from current directory and below, once is found i need to replace it with new ip addresse. Here is what i have but not complete.
Find IP from... (4 Replies)
Hi all,
I have a file with X number of lines.
Somewhere within each line will be an email address following the format:
<telephone_number>@domain.net
Each line is not a set length and there are no delimiters to work with.
I want to write a script that extracts the telephone number... (3 Replies)
Hello,
Is there a link somewhere to my profile where I can change my email address to my new work email address? I have a new job and would like to receive a notification of responses to my new work address - how can I get that address to you without posting it online for everyone to see?
... (1 Reply)
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)
Discussion started by: jingi1234
1 Replies
9. Post Here to Contact Site Administrators and Moderators