Remove single @ on line from file


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Remove single @ on line from file

Hi All,


So I have to remove all the @hostnames from a file, the problem is, there are instances where @ is used for other things... For example:


example text:
Code:
@This is some text in between some at signs@
@This is some more text@
This is a line that will contain a username and his/her email - me@somehost.com
This is another email line - you@anotherhost.com

I need to remove the text after the @somehost.com and @anotherhost.com but leave the two previous @ bla bla bla @ lines.


Heres what I have tried:


Code:
cat * |egrep -v '@.*@'|sed 's/@.*/@REDACTED/'

This kind of works, but I need all the lines intact


Code:
sed 's/@.*/@REDACTED/'

This just removed all the test after the @. This would be ok, but we would like to have the other lines if possible - we do just want to secure the file from having hostnames.



Not sure how to accomplish this. Any advice would be appreciated.


Thanks!
Joe
# 2  
Hi
Code:
sed 's/@\w\+\.\w\+/@REDACTED/g'

or
Code:
sed 's/@\w\+\.\w\+/@REDACTED/3'

This User Gave Thanks to nezabudka For This Post:
# 3  
for a non-GNU sed - might be harden a bit more/better:
Code:
sed 's/@[^ ][^ ]*[.][^ ][^ ]*/@REDACTED/g' myFile

This User Gave Thanks to vgersh99 For This Post:
# 5  
Works with any Posix-compatible sed:
Code:
sed 's/\([[:alnum:]]\)@[[:alnum:]][-_.[:alnum:]]*/\1@REDACTED/g' file

By requiring a character before the @ it will not trigger on a @ at the beginning of the line.
This User Gave Thanks to MadeInGermany For This Post:
# 6  
And a lookbehind perlie you could try
Code:
perl -pe 's/(?<=\S@)\S+/\REDACTED/g' file


Last edited by Scrutinizer; 1 Week Ago at 10:09 PM..
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Remove single-line breaks only in document
p1ne
Regarding copy/pasted text of copyright-free book from archive.org (link below), in attempt to expand single-line-break paragraph text (not section headings or paragraph breaks) to wider right margin, Justify or Wrap in LIbreOffice is not working, and Find/Replace the paragraph mark ($) wraps all...... Shell Programming and Scripting
2
Shell Programming and Scripting
Remove multi line and single line comments
ahmedwaseem2000
Hi, I am trying to remove multi line and single line comments like examples below I have tried this pattern. it works fine for single line comments and multi line comments in a single line only. but this fails when the comments are extended in multiple lines as shown in the comment 2 of...... UNIX for Dummies Questions & Answers
3
UNIX for Dummies Questions & Answers
how to remove mutilple enrty in a single line in unix
kaprus
Hi, Below is a single line output. subsD,01 02 03 04 05 00 00 00 00 07 00 05,hlr,common,00000000 subsD,01 02 03 04 05 00 00 00 00 07 00 05,hlr,01,baoc|notActive|notInduced,activeAndOperative,notActive,notActive,noneDesignated,0,notActive|00|,notActive|00|,notActive|00|,notActive|00|30|,,...... UNIX for Dummies Questions & Answers
4
UNIX for Dummies Questions & Answers
Trying to remove single character from a line
Iz3k34l
Here is a sample code grep '903' -i user.txt | tail -2 | awk '{print $2}' | sed 's/B//g' the input file has data as such 903-xxx-xxxxB 903-xxx-xxxxB It is a dialer file i want to remove the "B" any help thanks... UNIX for Dummies Questions & Answers
5
UNIX for Dummies Questions & Answers
remove single-line comment
Icy002
Does anyone knows how to write a program to remove single-line comment in C program? that means it don't read anything behind //... Programming
3
Programming