Help with sed - replacing strings
I have an alias table and I need to make a global change due to a new mail server. I think I can do it with sed, but don't know how.
a sample line look like this skrutua06: sanhuda_krutua06@firstclass.choate.edu I need to change the format to firstinitialLASTNAME and change the mail server like this skrutua06: skrutua06@newserver.choate.edu How can I strip the characters before the underscore and replace it with just the first initial. I know how to simply change the server name after the @ sign. that part was easy. there will be a variable length string for each first name but they will all have a space or whitespace character after the semicolon. Thanks in advance. |
Hi,
This should work: sed -e 's/ \([a-z]\)[a-z]*_/ \1/' -e 's/firstclass/newserver/' <infile> The first substitution takes everything from the first space to the underscore and replaces it with the content of \([a-z]\), this is done with the \1 in the replace part. With the -e option you can string sed statement together. The second one should look familiar. Hope this helps. |
This might work also...
Code:
sed -e 's/[a-z]*_//g' file.txt |
Fantastic.
Thanks, you saved me lots of time.
It works perfectly. Tom Quote:
|
Hi,
@thulley: You're welcome :) @homey: Your given command deletes every character before, and including, the underscore. It does not leave the first character of that string, as desired by the OP. |
All times are GMT -5. The time now is 09:16 AM. |