just want to know the simplest solution to these:
how can I delete text in a.txt that are in b.txt using DOS
(a.txt & b.txt contains hundrends of text)
a.text
hfdjfhfjdfd
jjdhfjhkfkkf
jkfjjdfjdj
b.txt
dkhfkhf
hfdjfhfjdfd
jjdhfjhkfkkf
jkfjjdfjdj
jddkbskdjksk
bsdbvbdsdj
Thanks!
DOS is not a preferred way to do. This link has some details on how to remove data from a file. I am not an expert in DOS. The below information may be helpful to you.
http://www.computing.net/answers/programming/delete-text-in-txt-files-with-dos/12552.html
Below contents are from the website given above
If "in DOS" means Win XP/2K prompt, as I suspect, that can be achieved by For /F statement. Something as
For /F "tokens=1*" %%A in (Text_File) Do (
Echo horse %%B >> New_Text_File)
Move New_Text_File Text_File /Y
but you get a solution only if you can understand it.
Related
This is the content of my .txt file
123:456
789:333
I'm trying to use findstr to read string and search for 789:333, but it only print fist line 123:456
As I know, use cut can fulfill my requirement in Linux.
In Windows, do we have any method where we can search for a string in a file by using a batch-script?
it is simple. using a for loop.
#echo off
for /F "delims=" %%a in ('findstr /I "789:333" somefile.txt') do echo %%a
you can learn a lot about batch file commands by simply opening a cmd.exe window and typing help
It describes briefly each command and once you find one that you think might work, like let's say for, then you simply do for /? which will show you help content which will make your life easy.
Please note I'm new to scripting so please be gentle!
I have a text file called list.txt with just one line (for testing), the line is:
D:\italy\gfm\users\test\avisgfm_1001_1500.txt
My script is:
#echo off
for /f "delims=" %%1 in (list.txt) do (
echo %%~1
echo %%~d1
echo %%~p1
echo %%~n1
echo %%~x1
)
However the result from the script is:
´╗┐d:\italy\gfm\users\test\avisgfm_1001_1500.txt
C:
\PCI\´╗┐d:\italy\gfm\users\test\avisgfm_1001_1500.txt
Any idea whats going on? I'm doing this via a Windows Batch file.
Thanks
The metavariable should be a (case-sensitive) letter.
Numbers refer to parameters to the routine.
for /f "delims=" %%a in (list.txt) do (
echo %%~a
and so on will work fine.
It seems you've saved list.txt with some encoding like UTF-8 with byte order mark at the head of file. BAT can process only ASCII text files. Try to create list.txt as simple ASCII text file. Notepad form Windows can do that.
%%1 works fine but it's better to use letter, for example %%i, as in for spec.
I'm an absolute beginner in Windows script and i'm required to do the following :(
for /f %%f in '..\dir\'
# Create a text file titled '\dir\filename.bat', containing " xxxx <filename> xxxx"
Once that's done i'd then run all the batch files created simultaneously
cd ..\dir
for /f %%f in * do
start cmd.exe /C '%%f.bat'
I'd really appreciate it if someone could tell me how to do the file creation part and also verify the rest of the code.
I'm not sure what your trying to do here...
If you want to make a file, you can just echo the line and append it ot a file (if the file does not exist, it will be created)... So for the st part of your question.
cd \dir
for /f %%f in ('dir /b') do (
echo "xxxx %%f xxxx" >> %%f.bat
echo "second line of file if required.." >> %%f.bat
echo "repeat for as many lines as you need.." >> %%f.bat
)
Not sure why you would want to run all the files together either... a lot of tiles may well cause ssues if they all open at once...
It would be more help if you could explain exactly what you needed to do, so people could perhaps offer better ways of achieveing the end result.
Edit
I've changed the code above so that it will work (I've tested, and it does what I think you need it to).
I have a list of files in a folder that end with .swf.
I want to change all those files from X.swf to X<some number>.swf.
How can I do that?
This little script will change all *.swf files into the equivalent *_42.swf files.
#setlocal enableextensions enabledelayedexpansion
#echo off
for /f %%a in ('dir /b *.swf') do (
set fspec=%%a
set newfspec=!fspec:~0,-4!_42.swf
echo ren !fspec! !newfspec!
)
endlocal
Actually, as it stands now, it will just echo the commands that it wants to execute. Once you're happy they're correct, you can just remove the echo from that renaming line above.
It works by using for /f to get a list of all SWF files and then using string manipulation to:
remove the last four characters (the.swf extension); then
add a new _42.swf extension onto the end.
And, please, make sure you back them up first :-)
You could use the following one-liner directly from the command prompt:
FOR %F IN (*.swf) DO RENAME "%F" "%~nF123.*"
where 123 stands for your number of choice.
Alternatively you could create a batch file and take advantage of its ability to accept parameters. Use the following script:
#ECHO OFF
SET "suffix=%~1"
FOR %%F IN (*.swf) DO RENAME "%%F" "%%~nF%suffix%.*"
Now if the batch's name is renamer.bat, you can invoke it like this:
renamer.bat 2011
and it will add 2011 to the name of every .swf file in the current directory.
Assuming <X> in your description is supposed to be constant and you don't explicitly require a batch script to solve your problem, you can use Windows Explorer as mentioned in an article by Microsoft titled "Rename a file".
Here's a an extract from said article:
"You can also rename several files at one time, which is useful for grouping related items. To do this, select the files [then press F2]. Type one name, and then each of the files will be saved with the new name and a different sequential number at the end (for example, Renamed File (2), Renamed File (3), and so on)."
i have an edited version of a config file specific for my machine.
i have the same config file in multiple different directories in my development folder.
i want to, in a single bat file, replace all instances of this file with my edited one.
So in pusedo code:
Take C:\edited.config and copy to C:\Projects\ /s wherever original.config is found
i want the final file to have the name of original.config, not edited.config
so i am guessing i need some combination of a FOR, a rename and copy or something like that
is this easier to do in Powershell?
can anybody help?
Thanks
I blogged about this a little bit ago at http://jamesewelch.com/2008/05/01/how-to-write-a-dos-batch-file-to-loop-through-files/
I think your solution will look something similar to (below is untested but used to show general idea)
for /f %%a IN ('dir /b *.config') do copy c:\master.config %%a
There's probably a switch there on the copy to suppress file overwrite warnings, but I don't remember what the switch is. This will copy your master.config and overwrite your local file (variable of %%a).
I'm amazed what DOS batch file experts make work. Since I'm not one of them, I take an approach that's pragmatic for me. It might work for you as well.
Get a list of destination folders
C:
Cd\
Dir original.config /s > original.bat
Edit original.bat in your favorite text editor (I like Notepad++)
Search for "original.config" and replace with "" (empty string)
Insert the text "Xcopy C:\edited.config " at the front of each line
Proof-read the result to be sure it's what you want. If you're not sure put an "Echo " in front of each line for a dry run.
Run the batch file.
#echo off
C:
cd \Projects
FOR /F "tokens=*" %%G IN ('DIR /B /S original.config') DO xcopy /y c:\edited.config %%G