Solved

Search batch file and replace

Posted on 2014-10-20
8
363 Views
Last Modified: 2014-10-22
I have a list of email addresses (black list) that I want to parse and remove everything except the domain name this is a small sample of the list
n.hardy@konnect-force.com
nancy@justleadgen.com
natural.d@tanya-tech.com
natural.n@realtoryou.com

want to end up with just
konnect-force.com
justleadgen.com
tanya-tech.com
realtoryou.com

The trick is that the number of characters before the @ varies greatly so how can I solve this please. Thanks. Prefer a batch file solution but VB or powershell acceptable too.
0
Comment
Question by:Lionel MM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 40393160
You can split at the @ using a for command:

@echo off
(for /f "tokens=2 delims=@" %%d in ('type yourlist.txt') do echo %%d)>newlist.txt

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40393177
Or if you want it de-duped too, try something like this... gets all the domain names, sorts them into order into newlist.txt then runs down that line by line and outputs any unique lines.

Steve

@echo off
setlocal enabledelayedexpansion
(for /f "tokens=2 delims=@" %%d in ('type yourlist.txt') do echo %%d) | sort >newlist.txt

set line=
(for /f %%d in ('type newlist.txt') do (
  if not "!line!"=="%%~d" echo %%~d
  set line=%%~d
)) > deduped.txt

Open in new window

0
 
LVL 25

Author Comment

by:Lionel MM
ID: 40394367
WOW great that's more than I asked for so thanks--however when I run it all that happens is that the the email address list open in notepad and when/if I close it another blank one named newlist.txt opens up. This is what I am using
@echo off
setlocal enabledelayedexpansion
(for /f "tokens=2 delims=@" %%d in ('D:\Data\SPAM.txt') do echo %%d) | sort >D:\Data\newlist.txt

set line=
(for /f %%d in ('D:\Data\NewList.txt') do (
  if not "!line!"=="%%~d" echo %%~d
  set line=%%~d
)) > D:\Data\deduped.txt
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:Steve Knight
ID: 40394765
try the word "type" before the path as in example above... I prefer that way to just listing the path (which would be without the ' ' around it.

Steve
0
 
LVL 25

Author Comment

by:Lionel MM
ID: 40394869
ok that does something but this is what I end up with in C:\Data\deduped.txt
C:\Utils>(
if not "!line!" == "2cjesus.com" echo 2cjesus.com  
 set line=2cjesus.com
)
2cjesus.com

C:\Utils>(
if not "!line!" == "acumatica.com" echo acumatica.com  
 set line=acumatica.com
)
acumatica.com

C:\Utils>(
if not "!line!" == "advhpc.com" echo advhpc.com  
 set line=advhpc.com
)
advhpc.com
deduped.txt
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40394937
Looks like you don't have @echo off ?

Steve
0
 
LVL 25

Author Closing Comment

by:Lionel MM
ID: 40396936
Thanks
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40396945
np, you got it working then I presume.

Steve
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question