Question:
How do I search and replace everything before 'x'? in a text file?
anonymous
1970-01-01 00:00:00 UTC
How do I search and replace everything before 'x'? in a text file?
Five answers:
Chris
2012-06-30 09:17:22 UTC
This is the type of thing that sed (stream editor) was created to do.



The command would be:



sed 's/^.*,//' inputfilename



Basically, sed applies a script to each line of an input file and then sends the output of that script to the standard out. In the example above, 's/^.*,//' is the script. The leading s identifies it as a search and replace command where the search expression is between the first two forward slashes and the replace expression is between the last two forward slashes. So this command searches for "^.*," and replaces it with "" (an empty string) for each line of the input file.



The search expression is a regular expression. The "^" character means "match from the beginning of the line." The "." (period) means "match any character." The "*" means "match zero or more times." And finally, the "," (comma) means "match a comma." Taken all together, this means, "match everything from the beginning of the line up to and including the first comma and replace it with an empty string."



Sed is a standard utility that is available on any unix/linux system. You can download a free copy for windows - just search google for something like "sed for windows".
anonymous
2016-11-30 06:45:30 UTC
it is previous the features of living house windows DOS/Command on the spot. it relatively is basic to do in Linux/Unix, the place a script can call techniques mutually with sed and awk. DOS does not have a seek-and-replace function. you will might desire to write a software to do this.
PratsPro
2012-06-30 06:13:53 UTC
go to find option in edit or near by ones dont remember the coreect one and search *.com it will show all the results select all and delete..:)
anonymous
2012-06-30 05:35:43 UTC
if you could paste into excel - then you could do it with formulas.



if you put text with the format "myemail@domain.com,first name, last name" into cell A1



the formula =RIGHT(A1,LEN(A1)-FIND(",",A1,1))



would turn that cell into "first name, last name"



actually the formula doesnt look at the ".com" - its looking for the first comma and deleting everything before it (i.e. the email address)
The Outcaste
2012-06-30 16:10:18 UTC
Copy and paste the following into Notepad:

::::::::

@Echo Off

Set _Filename=C:\DTest\emailNames.txt

Set _Newname=C:\DTest\Justname.txt

If Exist "%_Newname%" Del "%_Newname%"

For /F "Tokens=2,3 Delims=," %%I In ('Type "%_Filename%"') Do Echo.%%I,%%J>>"%_Newname%"

::::::::



Edit the Filename line to the path where your file are located, and the Newname line to where you want the new file to be.

If you want them on your desktop,m use %Username%\Desktop\emailNames.txt.



Save the file someplace handy with a .cmd extension. In the NOtepad Save dialog, be sure to change the Save As Type box to All FIles.

Double click the file to create the new file


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...