Computer Hope
Microsoft => Microsoft DOS => Topic started by: chandru630 on January 23, 2014, 05:24:17 AM
-
Hi All,
I want a batch file to do a task mentioned below:
input.txt
hi how you?
123 123 123
output
hi how are you?
123 123 are 123
-
Why?
-
I have to complete a task like this. So, i need batch file for this task.
-
You could get a batch file to solve your fake data, and it may not work on the real data due to character sets and special characters and numbers of characters.
If you show the actual data, replacing some characters to hide any confidential words but not changing the length of the words, then you might find people more willing to have look.
-
Ah, just link them to Repl and Findrepl usage threads on dostips. Not that they would be able to figure out how to use them.
Personally pretty easy to do this with vbscript. I like the replace option in Vbscript.
-
You can do this with a for loop, the word "are" is in the same spot in both lines.
-
Hi All,
I am writing the sample for my batch file.
a text file contains the following data
#define Symbol_Text Characters ( s_textW100H20A, 1, 2)
#define Graphic_Image Rect ( s_ImageW150H32A, 14, 222)
#define Icon_shape position ( s_iconW88H40A, 41, 25)
#define calculate_total msize ( s_ImageW66H66A, 11, 72)
like this a file contains more than 100's of lines.
the output should be like this:
#define Symbol_Text "New Macro" Characters ( s_textW100H20A, 1, 2)
#define Graphic_Image "New Macro" Rect ( s_ImageW150H32A, 14, 222)
#define Icon_shape "New Macro" position ( s_iconW88H40A, 41, 25)
#define calculate_total "New Macro" msize ( s_ImageW66H66A, 11, 72)
Pls help me to do this task. Thanks in advance.
-
This uses a helper batch file called `repl.bat` - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
@echo off
type "file.txt"|repl "(.* .*) (.* \(.*)" "$1 \qNew Macro\q $2" x >"Newfile.txt"
-
you can use awk for windows (http://gnuwin32.sourceforge.net/packages/gawk.htm)
C:\> type myFile.txt
#define Symbol_Text Characters ( s_textW100H20A, 1, 2)
#define Graphic_Image Rect ( s_ImageW150H32A, 14, 222)
#define Icon_shape position ( s_iconW88H40A, 41, 25)
#define calculate_total msize ( s_ImageW66H66A, 11, 72)
C:\>awk "{$3=$3\" \042New Macro\042\"}1" myFile.txt
#define Symbol_Text Characters "New Macro" ( s_textW100H20A, 1, 2)
#define Graphic_Image Rect "New Macro" ( s_ImageW150H32A, 14, 222)
#define Icon_shape position "New Macro" ( s_iconW88H40A, 41, 25)
#define calculate_total msize "New Macro" ( s_ImageW66H66A, 11, 72)
-
This uses a helper batch file called `repl.bat` - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
@echo off
type "file.txt"|repl "(.* .*) (.* \(.*)" "$1 \qNew Macro\q $2" x >"Newfile.txt"
nah, i wouldn't go for a regex solution for this case. A simple DOS for loop, get the 3rd token and concatenate the new string is better and more readable .
-
hi Briandams,
its works for me...Thanks you so much for your reply..