0

I've a data files with information like this :

977.txt:ahdcompany@yemen.net.ye
977.txt:ahemdrasheed@yemen.nrt.ye
980.txt:ahmedmohammed@y.ne.ye
982.txt:qfofs@yemen.net.ye
985.txt:agencysabaship@y.net.ye
987.txt:aghani@y.net.ye
987.txt:agk46@india.yellowpages.net.com
991.txt:aige_yemen@y.net.ye
991.txt:aige_yemen@y.net.ye
991.txt:aihaidechenmo@163.yeah.net
994.txt:qichange@163.yeah.net
995.txt:aina@email.yes
999.txt:aisco@y.net.ye

i want to remove everything before : how can i do that for all files in directory ( Linux ).

i've tried this, and it's working but i'm unable to use it with multiple files:

grep -o - '[[:alnum:]+\._\-]*@[[:alnum:]+\._\-]*' file.txt
  • Yes , i've tried grep grep -o - '[[:alnum:]+\._\-]*@[[:alnum:]+\._\-]*' file.txt and it's working but i'm unable to use it with multiple files – Arabiabitz Jan 13 at 23:50
  • use grep -h so that the file names are not displayed – PotroNik Jan 14 at 7:22
  • Did you use grep to create the file? If so, consider using grep -h to avoid prefixing the matches with the filename. You then wouldn't need to post-process it. – roaima Jan 14 at 7:40
1

Another sed solution.

$ sed -n 's/[^:]*\://p' infile
ahdcompany@yemen.net.ye
ahemdrasheed@yemen.nrt.ye
ahmedmohammed@y.ne.ye
qfofs@yemen.net.ye
agencysabaship@y.net.ye
aghani@y.net.ye
agk46@india.yellowpages.net.com
aige_yemen@y.net.ye
aige_yemen@y.net.ye
aihaidechenmo@163.yeah.net
qichange@163.yeah.net
aina@email.yes
aisco@y.net.ye
$

This can easily be extended to do in-place editing using the -i option, and to recursively edit files in a directory tree using find

| improve this answer | |
0

To delete the leading part in all you files in a single directory:

sed -i -r 's/^[0-9]+\.txt://' *

Test on a copy of a few files first.

| improve this answer | |
0

Depending on how much files is involve or how deep the directory goes, you might hit some errors but for small set of files this should work with ed.

 printf '%s\n' 'g/^.*:\(.*\)/s//\1/' w q | ed -s *
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.