I need to window bat file which will be placed in the server path.
Where my all data files are placed in other path.
1. Once I run the bat file, it should search the list of files in the given path
2. It should search for forward slash(/), back slash(),special characters and latin character set (like ä and etc., ) in the each file and replace with spaces.
Original File looks like
Corrected file
Aance petty cash - Site 21/03/2019||Y|17-OCT-19|17-OCT-19|17-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|S|158 \\fpp01\Finance\Finance\AP_PROCESSING\1_MEN|SAR
Aance petty cash - Site 21/03/2019||Y|17-OCT-19|17-OCT-19|17-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|S|\krv|SAR
Aance petty cash - Site 21/03/2019||Y|17-OCT-19|17-OCT-19|17-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|M|sd01\Finance\Finance\AP_PROCESSING\1_MEN |SAR
Aance petty cash - Site 21/03/2019||Y|17-OCT-19|17-OCT-19|17-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|M|159\fpp01\Finance\Finance\AP_PROCESSING\1_MEN |SAR
Studying and updating dmmmy ||Y|17-OCT-19|18-OCT-19|18-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|T|160 -|SAR
Johannes Märkl Monatsrechnung ----||N|17-OCT-19|18-OCT-19|18-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|S||SAR
after correcting the file
Aance petty cash - Site 21 03 2019||Y|17-OCT-19|17-OCT-19|17-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|S|158 fpp01 Finance Finance AP_PROCESSING 1_MEN|SAR
Aance petty cash - Site 21 03 2019||Y|17-OCT-19|17-OCT-19|17-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|S| krv|SAR
Aance petty cash - Site 21 03 2019||Y|17-OCT-19|17-OCT-19|17-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|M|sd01 Finance Finance AP_PROCESSING 1_MEN |SAR
Aance petty cash - Site 21 03 2019||Y|17-OCT-19|17-OCT-19|17-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|M|159 fpp01 Finance Finance AP_PROCESSING 1_MEN |SAR
Studying and updating dmmmy ||Y|17-OCT-19|18-OCT-19|18-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|T|160 -|SAR
Johannes Märkl Monatsrechnung ----||N|17-OCT-19|18-OCT-19|18-OCT-19|KMADRZYK|MANUAL W|SAKM18OCT19|S||SAR
this kind of many files will be present in the server path.
So, I need to search for each file and correct them.
You should use Regex in vbscript with a batch file : You can see Demo here
#echo off
Title Replace String using Regex with vbscript
Set "InputFile=Test.txt"
Set "TmpFile=%Tmp%\%~n0.txt"
:: To write Result in a temporary file
Call :Search_Replace "%InputFile%" "%TmpFile%"
:: Replace and move contents from the temporary file to the original
Move /Y "%TmpFile%" "%InputFile%">nul
Start "" "%InputFile%" & Exit
::-----------------------------------------------------------------------------------
:Search_Replace <InputFile> <TmpFile>
(
echo WScript.StdOut.WriteLine Search_Replace(Data^)
echo Function Search_Replace(Data^)
echo Dim strPattern, strReplace, strResult,oRegExp
echo Data = "%~1"
echo Data = WScript.StdIn.ReadAll
echo strPattern = "[\\\/\/]"
echo strReplace = " "
echo Set oRegExp = New RegExp
echo oRegExp.Global = True
echo oRegExp.IgnoreCase = True
echo oRegExp.Pattern = strPattern
echo strResult = oRegExp.Replace(Data,strReplace^)
echo Search_Replace = strResult
echo End Function
)>"%tmp%\%~n0.vbs"
cscript /U //nologo "%tmp%\%~n0.vbs" < "%~1" > "%~2"
If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
Exit /B
::----------------------------------------------------------------------------------
So I was working on a batch file game a while ago, and for some reason it prints a question mark symbol instead of the smiley face symbol (which you get when you press Ctrl+A in a command prompt).
My Program ScreenShot
I have the same problem with these others symbols:
ctrl+a Smiley face
ctrl+b Dark smiley face
ctrl+d Diamond
ctrl+e Clover
ctrl+f Ace
ctrl+n Music symbol
crtl+o Some random circlish symbol
ctrl+p Left arrow
ctrl+q Right arrow
ctrl+r Up and Down arrows
ctrl+t Line wrap symbol
ctrl+u Double s
ctrl+v Thick underscore
ctrl+w Up and down arrow with a line at the bottom
ctrl+x Up arrow
ctrl+y Down arrow
Source from Instructables Article: How do you use special characters in cmd
I tried it with cmd ScreenShot
I am currently running Windows 10 Pro with the latest update. I have tried to find a solution to fix this problem but had no success. Any help would be appreciated.
The behavior of OEM Alt codes is misleading for codes 1-31 and 127. The system's OEM codepage is a superset of ASCII. However, this range of Alt codes doesn't input ASCII control characters, but rather the characters that old IBM PC systems would sometimes display and print for ASCII control characters. For example, Alt+1 enters "☺" (U+263A, white smiling face) instead of ASCII SOH (U+0001, start of heading). To compound this, the default behavior of WideCharToMultiByte when encoding such characters to the OEM codepage is to use the corresponding ASCII control character as the best-fit encoding. So a text editor may not warn you that what you see is not what you'll get.
The console doesn't display control characters as the old IBM PC graphics characters. It interprets some of them such as U+0009 (horizontal tab -- advance the cursor 8 spaces) and U+000D (carriage return -- advance the cursor to the beginning of the next line), but most of them are displayed as the current font's glyph for an unmapped character, such as a boxed question mark or an empty box. If you want to print "☺" to the console, then you should use the console's wide-character API, which works with Windows native Unicode (UTF-16LE) strings.
Fortunately CMD is a Unicode application, so there's no problem with printing "☺" to the console. The problem is what encoding to use for the batch script. The only general solution is to save the batch file as UTF-8 without a BOM (byte order mark). You'll need an IDE or text editor that can save UTF-8 without a BOM, such as Notepad++.
CMD decodes a batch script line by line using the legacy console codepage, which you can change to UTF-8 with the command chcp.com 65001. I advise against changing to UTF-8 permanently because, depending on the Windows version, the console has various bugs with codepage 65001. You can switch to UTF-8 temporarily to load non-ASCII strings as environment variables. Otherwise keep the rest of the batch file as strictly 7-bit ASCII to avoid localization problems.
Here's an example. There is probably a more generalized way to go about this than creating all of these local environment variables, but it's just to show that it works in principle.
graphics_ctl.bat
#echo off
REM ASCII Control-Character Graphics
REM File encoding: UTF-8 (no BOM)
REM Set the console to codepage 65001 (UTF-8).
for /f "tokens=2 delims=:" %%a in ('chcp.com') do set "CONSOLE_CODEPAGE=%%a"
set "CONSOLE_CODEPAGE=%CONSOLE_CODEPAGE: =%"
chcp.com 65001 >NUL
set "GCTL_WHITE_SMILING_FACE=☺"
set "GCTL_BLACK_SMILING_FACE=☻"
set "GCTL_BLACK_HEART_SUIT=♥"
set "GCTL_BLACK_DIAMOND_SUIT=♦"
set "GCTL_BLACK_CLUB_SUIT=♣"
set "GCTL_BLACK_SPADE_SUIT=♠"
set "GCTL_BULLET=•"
set "GCTL_INVERSE_BULLET=◘"
set "GCTL_WHITE_CIRCLE=○"
set "GCTL_INVERSE_WHITE_CIRCLE=◙"
set "GCTL_MALE_SIGN=♂"
set "GCTL_FEMALE_SIGN=♀"
set "GCTL_EIGHTH_NOTE=♪"
set "GCTL_BEAMED_EIGHTH_NOTES=♫"
set "GCTL_WHITE_SUN_WITH_RAYS=☼"
set "GCTL_BLACK_RIGHT_POINTER=►"
set "GCTL_BLACK_LEFT_POINTER=◄"
set "GCTL_UP_DOWN_ARROW=↕"
set "GCTL_DOUBLE_EXCLAMATION_MARK=‼"
set "GCTL_PILCROW_SIGN=¶"
set "GCTL_SECTION_SIGN=§"
set "GCTL_BLACK_RECTANGLE=▬"
set "GCTL_UP_DOWN_ARROW_WITH_BASE=↨"
set "GCTL_UP_ARROW=↑"
set "GCTL_DOWN_ARROW=↓"
set "GCTL_RIGHT_ARROW=→"
set "GCTL_LEFT_ARROW=←"
set "GCTL_RIGHT_ANGLE=∟"
set "GCTL_LEFT_RIGHT_ARROW=↔"
set "GCTL_BLACK_UP_TRIANGLE=▲"
set "GCTL_BLACK_DOWN_TRIANGLE=▼"
set "GCTL_HOUSE=⌂"
REM Restore the previous console codepage.
chcp.com %CONSOLE_CODEPAGE% >NUL
graphics_box.bat
#echo off
REM Box-Drawing Graphics
REM File encoding: UTF-8 (no BOM)
REM Set the console to codepage 65001 (UTF-8).
for /f "tokens=2 delims=:" %%a in ('chcp.com') do set "CONSOLE_CODEPAGE=%%a"
set "CONSOLE_CODEPAGE=%CONSOLE_CODEPAGE: =%"
chcp.com 65001 >NUL
set "GBOX_LIGHT_SHADE=░"
set "GBOX_MEDIUM_SHADE=▒"
set "GBOX_DARK_SHADE=▓"
set "GBOX_LIGHT_VERTICAL=│"
set "GBOX_LIGHT_VERTICAL_AND_LEFT=┤"
set "GBOX_VERTICAL_SINGLE_AND_LEFT_DOUBLE=╡"
set "GBOX_VERTICAL_DOUBLE_AND_LEFT_SINGLE=╢"
set "GBOX_DOWN_DOUBLE_AND_LEFT_SINGLE=╖"
set "GBOX_DOWN_SINGLE_AND_LEFT_DOUBLE=╕"
set "GBOX_DOUBLE_VERTICAL_AND_LEFT=╣"
set "GBOX_DOUBLE_VERTICAL=║"
set "GBOX_DOUBLE_DOWN_AND_LEFT=╗"
set "GBOX_DOUBLE_UP_AND_LEFT=╝"
set "GBOX_UP_DOUBLE_AND_LEFT_SINGLE=╜"
set "GBOX_UP_SINGLE_AND_LEFT_DOUBLE=╛"
set "GBOX_LIGHT_DOWN_AND_LEFT=┐"
set "GBOX_LIGHT_UP_AND_RIGHT=└"
set "GBOX_LIGHT_UP_AND_HORIZONTAL=┴"
set "GBOX_LIGHT_DOWN_AND_HORIZONTAL=┬"
set "GBOX_LIGHT_VERTICAL_AND_RIGHT=├"
set "GBOX_LIGHT_HORIZONTAL=─"
set "GBOX_LIGHT_VERTICAL_AND_HORIZONTAL=┼"
set "GBOX_VERTICAL_SINGLE_AND_RIGHT_DOUBLE=╞"
set "GBOX_VERTICAL_DOUBLE_AND_RIGHT_SINGLE=╟"
set "GBOX_DOUBLE_UP_AND_RIGHT=╚"
set "GBOX_DOUBLE_DOWN_AND_RIGHT=╔"
set "GBOX_DOUBLE_UP_AND_HORIZONTAL=╩"
set "GBOX_DOUBLE_DOWN_AND_HORIZONTAL=╦"
set "GBOX_DOUBLE_VERTICAL_AND_RIGHT=╠"
set "GBOX_DOUBLE_HORIZONTAL=═"
set "GBOX_DOUBLE_VERTICAL_AND_HORIZONTAL=╬"
set "GBOX_UP_SINGLE_AND_HORIZONTAL_DOUBLE=╧"
set "GBOX_UP_DOUBLE_AND_HORIZONTAL_SINGLE=╨"
set "GBOX_DOWN_SINGLE_AND_HORIZONTAL_DOUBLE=╤"
set "GBOX_DOWN_DOUBLE_AND_HORIZONTAL_SINGLE=╥"
set "GBOX_UP_DOUBLE_AND_RIGHT_SINGLE=╙"
set "GBOX_UP_SINGLE_AND_RIGHT_DOUBLE=╘"
set "GBOX_DOWN_SINGLE_AND_RIGHT_DOUBLE=╒"
set "GBOX_DOWN_DOUBLE_AND_RIGHT_SINGLE=╓"
set "GBOX_VERTICAL_DOUBLE_AND_HORIZONTAL_SINGLE=╫"
set "GBOX_VERTICAL_SINGLE_AND_HORIZONTAL_DOUBLE=╪"
set "GBOX_LIGHT_UP_AND_LEFT=┘"
set "GBOX_LIGHT_DOWN_AND_RIGHT=┌"
set "GBOX_FULL_BLOCK=█"
set "GBOX_LOWER_HALF_BLOCK=▄"
set "GBOX_LEFT_HALF_BLOCK=▌"
set "GBOX_RIGHT_HALF_BLOCK=▐"
set "GBOX_UPPER_HALF_BLOCK=▀"
REM Restore the previous console codepage.
chcp.com %CONSOLE_CODEPAGE% >NUL
graphics_test.bat
#echo off
setlocal
set "scriptdir=%~dp0"
call "%scriptdir%\graphics_ctl.bat"
call "%scriptdir%\graphics_box.bat"
echo.
echo ASCII Control-Character Graphics
echo ----------------------------------------------
echo GCTL_WHITE_SMILING_FACE = %GCTL_WHITE_SMILING_FACE%
echo GCTL_BLACK_SMILING_FACE = %GCTL_BLACK_SMILING_FACE%
echo GCTL_BLACK_HEART_SUIT = %GCTL_BLACK_HEART_SUIT%
echo GCTL_BLACK_DIAMOND_SUIT = %GCTL_BLACK_DIAMOND_SUIT%
echo GCTL_BLACK_CLUB_SUIT = %GCTL_BLACK_CLUB_SUIT%
echo GCTL_BLACK_SPADE_SUIT = %GCTL_BLACK_SPADE_SUIT%
echo GCTL_BULLET = %GCTL_BULLET%
echo GCTL_INVERSE_BULLET = %GCTL_INVERSE_BULLET%
echo GCTL_WHITE_CIRCLE = %GCTL_WHITE_CIRCLE%
echo GCTL_INVERSE_WHITE_CIRCLE = %GCTL_INVERSE_WHITE_CIRCLE%
echo GCTL_MALE_SIGN = %GCTL_MALE_SIGN%
echo GCTL_FEMALE_SIGN = %GCTL_FEMALE_SIGN%
echo GCTL_EIGHTH_NOTE = %GCTL_EIGHTH_NOTE%
echo GCTL_BEAMED_EIGHTH_NOTES = %GCTL_BEAMED_EIGHTH_NOTES%
echo GCTL_WHITE_SUN_WITH_RAYS = %GCTL_WHITE_SUN_WITH_RAYS%
echo GCTL_BLACK_RIGHT_POINTER = %GCTL_BLACK_RIGHT_POINTER%
echo GCTL_BLACK_LEFT_POINTER = %GCTL_BLACK_LEFT_POINTER%
echo GCTL_UP_DOWN_ARROW = %GCTL_UP_DOWN_ARROW%
echo GCTL_DOUBLE_EXCLAMATION_MARK = %GCTL_DOUBLE_EXCLAMATION_MARK%
echo GCTL_PILCROW_SIGN = %GCTL_PILCROW_SIGN%
echo GCTL_SECTION_SIGN = %GCTL_SECTION_SIGN%
echo GCTL_BLACK_RECTANGLE = %GCTL_BLACK_RECTANGLE%
echo GCTL_UP_DOWN_ARROW_WITH_BASE = %GCTL_UP_DOWN_ARROW_WITH_BASE%
echo GCTL_UP_ARROW = %GCTL_UP_ARROW%
echo GCTL_DOWN_ARROW = %GCTL_DOWN_ARROW%
echo GCTL_RIGHT_ARROW = %GCTL_RIGHT_ARROW%
echo GCTL_LEFT_ARROW = %GCTL_LEFT_ARROW%
echo GCTL_RIGHT_ANGLE = %GCTL_RIGHT_ANGLE%
echo GCTL_LEFT_RIGHT_ARROW = %GCTL_LEFT_RIGHT_ARROW%
echo GCTL_BLACK_UP_TRIANGLE = %GCTL_BLACK_UP_TRIANGLE%
echo GCTL_BLACK_DOWN_TRIANGLE = %GCTL_BLACK_DOWN_TRIANGLE%
echo GCTL_HOUSE = %GCTL_HOUSE%
echo.
echo Box-Drawing Graphics
echo ----------------------------------------------
echo GBOX_LIGHT_SHADE = %GBOX_LIGHT_SHADE%
echo GBOX_MEDIUM_SHADE = %GBOX_MEDIUM_SHADE%
echo GBOX_DARK_SHADE = %GBOX_DARK_SHADE%
echo GBOX_LIGHT_VERTICAL = %GBOX_LIGHT_VERTICAL%
echo GBOX_LIGHT_VERTICAL_AND_LEFT = %GBOX_LIGHT_VERTICAL_AND_LEFT%
echo GBOX_VERTICAL_SINGLE_AND_LEFT_DOUBLE = %GBOX_VERTICAL_SINGLE_AND_LEFT_DOUBLE%
echo GBOX_VERTICAL_DOUBLE_AND_LEFT_SINGLE = %GBOX_VERTICAL_DOUBLE_AND_LEFT_SINGLE%
echo GBOX_DOWN_DOUBLE_AND_LEFT_SINGLE = %GBOX_DOWN_DOUBLE_AND_LEFT_SINGLE%
echo GBOX_DOWN_SINGLE_AND_LEFT_DOUBLE = %GBOX_DOWN_SINGLE_AND_LEFT_DOUBLE%
echo GBOX_DOUBLE_VERTICAL_AND_LEFT = %GBOX_DOUBLE_VERTICAL_AND_LEFT%
echo GBOX_DOUBLE_VERTICAL = %GBOX_DOUBLE_VERTICAL%
echo GBOX_DOUBLE_DOWN_AND_LEFT = %GBOX_DOUBLE_DOWN_AND_LEFT%
echo GBOX_DOUBLE_UP_AND_LEFT = %GBOX_DOUBLE_UP_AND_LEFT%
echo GBOX_UP_DOUBLE_AND_LEFT_SINGLE = %GBOX_UP_DOUBLE_AND_LEFT_SINGLE%
echo GBOX_UP_SINGLE_AND_LEFT_DOUBLE = %GBOX_UP_SINGLE_AND_LEFT_DOUBLE%
echo GBOX_LIGHT_DOWN_AND_LEFT = %GBOX_LIGHT_DOWN_AND_LEFT%
echo GBOX_LIGHT_UP_AND_RIGHT = %GBOX_LIGHT_UP_AND_RIGHT%
echo GBOX_LIGHT_UP_AND_HORIZONTAL = %GBOX_LIGHT_UP_AND_HORIZONTAL%
echo GBOX_LIGHT_DOWN_AND_HORIZONTAL = %GBOX_LIGHT_DOWN_AND_HORIZONTAL%
echo GBOX_LIGHT_VERTICAL_AND_RIGHT = %GBOX_LIGHT_VERTICAL_AND_RIGHT%
echo GBOX_LIGHT_HORIZONTAL = %GBOX_LIGHT_HORIZONTAL%
echo GBOX_LIGHT_VERTICAL_AND_HORIZONTAL = %GBOX_LIGHT_VERTICAL_AND_HORIZONTAL%
echo GBOX_VERTICAL_SINGLE_AND_RIGHT_DOUBLE = %GBOX_VERTICAL_SINGLE_AND_RIGHT_DOUBLE%
echo GBOX_VERTICAL_DOUBLE_AND_RIGHT_SINGLE = %GBOX_VERTICAL_DOUBLE_AND_RIGHT_SINGLE%
echo GBOX_DOUBLE_UP_AND_RIGHT = %GBOX_DOUBLE_UP_AND_RIGHT%
echo GBOX_DOUBLE_DOWN_AND_RIGHT = %GBOX_DOUBLE_DOWN_AND_RIGHT%
echo GBOX_DOUBLE_UP_AND_HORIZONTAL = %GBOX_DOUBLE_UP_AND_HORIZONTAL%
echo GBOX_DOUBLE_DOWN_AND_HORIZONTAL = %GBOX_DOUBLE_DOWN_AND_HORIZONTAL%
echo GBOX_DOUBLE_VERTICAL_AND_RIGHT = %GBOX_DOUBLE_VERTICAL_AND_RIGHT%
echo GBOX_DOUBLE_HORIZONTAL = %GBOX_DOUBLE_HORIZONTAL%
echo GBOX_DOUBLE_VERTICAL_AND_HORIZONTAL = %GBOX_DOUBLE_VERTICAL_AND_HORIZONTAL%
echo GBOX_UP_SINGLE_AND_HORIZONTAL_DOUBLE = %GBOX_UP_SINGLE_AND_HORIZONTAL_DOUBLE%
echo GBOX_UP_DOUBLE_AND_HORIZONTAL_SINGLE = %GBOX_UP_DOUBLE_AND_HORIZONTAL_SINGLE%
echo GBOX_DOWN_SINGLE_AND_HORIZONTAL_DOUBLE = %GBOX_DOWN_SINGLE_AND_HORIZONTAL_DOUBLE%
echo GBOX_DOWN_DOUBLE_AND_HORIZONTAL_SINGLE = %GBOX_DOWN_DOUBLE_AND_HORIZONTAL_SINGLE%
echo GBOX_UP_DOUBLE_AND_RIGHT_SINGLE = %GBOX_UP_DOUBLE_AND_RIGHT_SINGLE%
echo GBOX_UP_SINGLE_AND_RIGHT_DOUBLE = %GBOX_UP_SINGLE_AND_RIGHT_DOUBLE%
echo GBOX_DOWN_SINGLE_AND_RIGHT_DOUBLE = %GBOX_DOWN_SINGLE_AND_RIGHT_DOUBLE%
echo GBOX_DOWN_DOUBLE_AND_RIGHT_SINGLE = %GBOX_DOWN_DOUBLE_AND_RIGHT_SINGLE%
echo GBOX_VERTICAL_DOUBLE_AND_HORIZONTAL_SINGLE = %GBOX_VERTICAL_DOUBLE_AND_HORIZONTAL_SINGLE%
echo GBOX_VERTICAL_SINGLE_AND_HORIZONTAL_DOUBLE = %GBOX_VERTICAL_SINGLE_AND_HORIZONTAL_DOUBLE%
echo GBOX_LIGHT_UP_AND_LEFT = %GBOX_LIGHT_UP_AND_LEFT%
echo GBOX_LIGHT_DOWN_AND_RIGHT = %GBOX_LIGHT_DOWN_AND_RIGHT%
echo GBOX_FULL_BLOCK = %GBOX_FULL_BLOCK%
echo GBOX_LOWER_HALF_BLOCK = %GBOX_LOWER_HALF_BLOCK%
echo GBOX_LEFT_HALF_BLOCK = %GBOX_LEFT_HALF_BLOCK%
echo GBOX_RIGHT_HALF_BLOCK = %GBOX_RIGHT_HALF_BLOCK%
echo GBOX_UPPER_HALF_BLOCK = %GBOX_UPPER_HALF_BLOCK%
Well, it depends on your code page. You can check it by going on command prompt and typing chcp, which well display your code page. Search it up and you'll find a list of characters you can write. Basically, it'll tell you which "special" characters you can type in that will be displayed. For example, mines is 850 (like a lot of others) and so can't display smiley faces. You can change your code page by:
Open Windows Control Panel
Select Region and Language
Click on the Administrative tab
Under Language for non-Unicode programs, click on Change System Locale
Choose the locale
Click OK
That's all, I think. Hope I helped!
I'm trying to make a batch file that reads a txt file "ayylmao.txt" and find a specific word "hello" and replaces it with "xello".
The thing is that the "ayylmao.txt" contains specific characters.
Ayylmao.txt looks something like this:
‹‹R‹Ę‹/M‹;Ču‹č˙˙˙‹‹#‰‹‹#CëC;Đu‹čq˙˙˙‹‹#C‹D$‰;7u®‹Ó‹Ćčúţ˙˙„Ŕu3Ŕ‰YZ]_^[ĂŤ# SVWUÄđ‰$‹ô‹‰D$‹
‹‹#;Č‚† ‹Ř‹>_‹ůz;ßrv;Ču!‹B‹A‹B‹)B‹x uV‹čđţ˙˙ëM‹Ř‹>_‹ůz;ßu
‹B‹)Bë3‹Z‰\$‹>‹‹.}+ű‰|$+Č‹‰HŤT$‹čMţ˙˙„Ŕu3 hello Ŕë°ë‹‹ ‰‹;D$…Y˙˙˙3ŔÄ]_^[ĂSVW‹Ú‹đţ }ľ ëĆ˙˙ ć ˙˙‰sjh Vj
You can see the "hello" word in the last line. I want the batch to go to the process and give me a ayylmao1.txt that looks like this:
‹‹R‹Ę‹/M‹;Ču‹č˙˙˙‹‹#‰‹‹#CëC;Đu‹čq˙˙˙‹‹#C‹D$‰;7u®‹Ó‹Ćčúţ˙˙„Ŕu3Ŕ‰YZ]_^[ĂŤ# SVWUÄđ‰$‹ô‹‰D$‹
‹‹#;Č‚† ‹Ř‹>_‹ůz;ßrv;Ču!‹B‹A‹B‹)B‹x uV‹čđţ˙˙ëM‹Ř‹>_‹ůz;ßu
‹B‹)Bë3‹Z‰\$‹>‹‹.}+ű‰|$+Č‹‰HŤT$‹čMţ˙˙„Ŕu3 xello Ŕë°ë‹‹ ‰‹;D$…Y˙˙˙3ŔÄ]_^[ĂSVW‹Ú‹đţ }ľ ëĆ˙˙ ć ˙˙‰sjh Vj
You can see that "hello" is now "xello".
I found this batch file that replaces a word from a text file:
#echo off
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
This code works for files that don't have specific characters very good if use it like this:
code.bat "hello" "xello" "ayylmao.txt">"ayylmao1.txt"
This code only types in ayylmao1.txt few special characters but replaces hello. I want all the special characters typed in there.
I made it like this:
chcp 1252
code.bat "hello" "xello" "ayylmao.txt">"ayylmao1.txt"
But it didn't work. It worked just like the first code.
If there is a way in PowerShell to do this I'd be glad to hear it.
What you have there looks like a binary file, not a text file, despite the extension. Batch is no good for editing binary files. In PowerShell it's doable, but you need to resort to working with the data bytes instead of simple text.
This is a basic example that will find the first occurrence of the string "hello" in your file and replace it with "xhello":
$f = 'C:\path\to\ayylmao.txt'
$stext = 'hello'
$rtext = [char[]]'xhello'
$len = $stext.Length
$offset = $len - 1
$data = [IO.File]::ReadAllBytes($f)
# find first occurrence of $stext in byte array
for ($i=0; $i -lt $data.Count - $offset; $i++) {
$slice = $data[$i..($i+$offset)]
if (-join [char[]]$slice -eq $stext) { break }
}
# Once you know the beginning ($i) and length ($len) of the array slice
# containing $stext you can "cut up" $data and concatenate the slices before
# and after $stext to the byte sequence you want to insert ($rtext):
#
# |<-- $stext -->|
# [...]['h','e','l','l','o'][...] <-- $data
# ^ ^ ^ ^
# | | | |
# | $i | $i+$len
# $i-1 $i+$offset (== $i+$len-1)
#
$rdata = $data[0..($i-1)] + [byte[]]$rtext + $data[($i+$len)..($data.Count-1)]
[IO.File]::WriteAllBytes($f, $rdata)
You'll need to adjust this code if you want the replacement to work differently (replace other occurrences as well, replace a different occurrence, …).
But it didn't work. It worked just like the first code. Help ?
This batch code is coming from this site and there is a link to discussion why it doesn't work with special characters.
Yes, the PowerShell replace command can replace the string and keep the special characters. To call it from within your batch script, use the following line
powershell -command "(get-content Ayylmao.txt) -replace 'hello','xello' | set-content Ayylmao.txt"
If you want to enter your parameters from the command line, then the line would be
powershell -command "(get-content %3) -replace '%1','%2' | set-content %4"
And if you want to use variables defined in the batch script, it is the same as you would for any batch script
set file=Ayylmao.txt
set Search_criteria=hello
set Replace_criteria=xello
powershell -command "(get-content %file%) -replace '%Search_criteria%','%Replace_criteria%' | set-content %file%"
I am writing a windows script to read in a txt file with 9 columns of data
I want to write this data out to a csv file to be loaded into a database.
I have found that one column is sometimes blank, so I would like to enter code 'rdp'
another column has mostly numbers, but for reason some values are a '.' (presumably indicating value less than 1. I would like to change these values to '0'
my code
for /F %%b in (c:\ts_users\newfiles_list.txt) do (
for /F "tokens=1,2,3,4,5,6,7,8,9" %%i in (%%b) do (
echo %%i,%%j,%%k,%%l,%%m,!idle!,%%o %%p,%%q >>%%~nb.csv
)
)
this manages to read in the txt file, then write it out as a csv.
column k is sometimes empty, column n sometimes has a '.'
I have tried variations of
set var=rdp
if %%k="" then set !k:=!var!
which doesnt work, so I a little stumped (after googling internet for days)
current input
201401241611 USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME eu1ptsw002
201401241611 julie.noble rdp-tcp#9 3 Active 18 24/01/2014 14:24 eu1ptsw002
201401241611 svc.perfmon18 7 Disc 3 24/01/2014 14:15 eu1ptsw002
201401241611 reto.hofstetter 10 Disc 40 24/01/2014 10:57 eu1ptsw002
201401241611 lester.valentin 14 Disc 1:16 24/01/2014 11:53 eu1ptsw002
201401241611 philippe.bachmann 15 Disc 2 24/01/2014 12:45 eu1ptsw002
201401241611 patrik.soderlund rdp-tcp#2 21 Active 24 24/01/2014 07:42 eu1ptsw002
current output
201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME
201401241611,julie.noble,rdp-tcp#9,3,Active,,24/01/2014 14:24,eu1ptsw002
201401241611,svc.perfmon18,7,Disc,3,,14:15 eu1ptsw002,
201401241611,reto.hofstetter,10,Disc,40,,10:57 eu1ptsw002,
201401241611,lester.valentin,14,Disc,1:16,,11:53 eu1ptsw002,
201401241611,philippe.bachmann,15,Disc,2,,12:45 eu1ptsw002,
201401241611,patrik.soderlund,rdp-tcp#2,21,Active,,24/01/2014 07:42,eu1ptsw002
required output
201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME
201401241611,julie.noble,rdp-tcp#9,3,Active,18,24/01/2014 14:24,eu1ptsw002
201401241611,svc.perfmon18,rdp,7,Disc,3,24/01/2014 14:15,eu1ptsw002
201401241611,reto.hofstetter,rdp,10,Disc,40,24/01/2014 10:57,eu1ptsw002,
201401241611,lester.valentin,rdp,14,Disc,1:16,24/01/2014 11:53,eu1ptsw002
201401241611,philippe.bachmann,rdp,15,Disc,2,24/01/2014 12:45,eu1ptsw002
201401241611,patrik.soderlund,rdp-tcp#2,21,Active,24,24/01/2014 07:42,eu1ptsw002
#echo off &setlocal disableDelayedExpansion
for /f "delims=" %%a in (file) do (
set "line=%%~a"
setlocal enabledelayedexpansion
set "line=!line:,.,=,0,!"
set "line=!line:,,=,rdp,!"
echo(!line!
endlocal
)
Is anyone aware of a library suitable for writing an image in .TMB format?
The .TMB format is suitable for printing logos from a Epson thermal receipt printer.
After about an hour or so of looking at binary data, I came to the following conclusion:
A *.TMB image is really just a serialized ESC/POS command to print a raster image.
Using the following command:
od -t a -v [YOUR_TMB_FILE] | head
we can view the binary data, as ASCII character data, in the beginning of the TMB file.
I had a file that looked something like this:
0000000 gs v 0 nul 5 nul P nul del del del del del del del del
0000020 del del del del del del del del del del del del del del del del
... snipped for brevity ...
According to the ESC/POS Programming Guide, the ASCII command to print a raster image is:
GS V 0
Hmm.. Interesting!
On a whim, I decided to convert 5 and P to their decimal equivalents, which are 53 and 80 respectively, the exact dimensions of my .TMB image (actually, its 80x53)!
Everything fell into place after this. The remainder of a .TMB file is just the binary image data.
Here is a one-off Python script I wrote to test my theory:
1 out = open('test.TMB', 'wb')
2
3 width = 80
4 height = 53
5
6 NUL = chr(0)
7 GS = chr(29)
8 V = chr(118)
9 ZERO = chr(48)
10
11 W = chr(width)
12 H = chr(height)
13
14 out.write(GS)
15 out.write(V)
16 out.write(ZERO)
17 out.write(NUL)
18
19 out.write(H)
20 out.write(NUL)
21 out.write(W)
22 out.write(NUL)
23
24 for y in range(0, height):
25 for x in range(0, width):
26 out.write(chr(127)) # looks like `del` in ASCII mode
27
28 out.close()