![]() |
|
|
|||||||
| Petri.co.il is happy to award auglan the title of Most Valuable Member !!! |
| Register | Calendar |
Search |
Today's Posts |
Mark Forums Read |
| Notices |
|
|
Search and Replace text via CMD?this thread has 6 replies and has been viewed 8882 times
|
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||||||
|
||||||||
|
I have a dga file (which can be opened and edited in notepad) that is generated by a third party application. I need to edit one line in the file. The file is called:
"%WORKING_DIRECTORY%\%SOURCE_FILENAME%-output.dga" Here is a portion of the file: Code:
DGAVCIndexFile7 C:\Personal\Videos\87943231_1280x532_23.976.h264 C:\Program Files\DGAVCIndex\ STREAM 0 FO 2 YUVRGB 1 LUMFILT 0 0 CLIP 0 0 0 0 RANGE 0 117586579 AUDIO --------Bulk of the file removed here since it takes up a lot of space-------- SIZ 1280 x 532 FPS 50 / 2 CODED 3339 PLAYBACK 3339 Last edited by rack04; 23rd June 2009 at 21:30.. |
|
#2
|
||||||||
|
||||||||
|
Initially I thought I could just use the find command but it adds the following text to the top of the file:
---------- %WORKING_DIRECTORY%\%SOURCE_FILENAME%-output.DGA Code:
find /V "FPS " "%WORKING_DIRECTORY%\%SOURCE_FILENAME%-output.dga" > "%WORKING_DIRECTORY%\%SOURCE_FILENAME%-output.dga0" echo FPS 24000 / 1001>>"%WORKING_DIRECTORY%\%SOURCE_FILENAME%-output.dga0" move /Y "%WORKING_DIRECTORY%\%SOURCE_FILENAME%-output.dga0" "%WORKING_DIRECTORY%\%SOURCE_FILENAME%-output.dga" Last edited by rack04; 23rd June 2009 at 22:06.. |
|
#3
|
||||||||||
|
||||||||||
|
similar thread: http://www.petri.co.il/forums/showpo...13&postcount=4
Code:
@echo off & setlocal enabledelayedexpansion
Set "inputFile=C:\test\test.txt"
Set "outputFile=%inputFile%-TMP.txt"
>"%outputFile%" (
For /f "delims=" %%* in (
'find.exe /n /v ""^<"%inputFile%"'
) Do (
Call:GoParse "''%%*"
(echo\!WriteLine!)
)
)
::# replace original file (! remove 'rem' !)
rem Move /Y "%outputFile%" "%inputFile%"
:end ----------
goto:eof
:GoParse lines
(Set /a i = %i% +1)&(Set Line=%1)
(Set Line=!Line:''[%i%]=!)&(Set "WriteLine=")
:: string substitution (is case-insensitive!)
:: http://www.robvanderwoude.com/ntset.php#StrSubst
(Set Line=%Line:FPS 50 / 2=FPS 24000 / 1001%)
(Set WriteLine=%Line:~1,-1%)
goto:eof
__________________
This posting is provided "AS IS" with no warranties, and confers no rights. __________________ ** Remember to give credit where credit's due ** and leave Reputation Points for meaningful posts |
|
#4
|
||||||||
|
||||||||
|
Thanks for all the help. I just have a couple more questions.
Here is where I stand: Code:
@SET WORKING_DIRECTORY=C:\Personal\Videos
@echo off & setlocal enabledelayedexpansion
set /p INPUT_VIDEO="Full path to DGA file: "
Move /Y "%INPUT_VIDEO%" "%WORKING_DIRECTORY%\test.txt"
Set "inputFile=%WORKING_DIRECTORY%\test.txt"
Set "outputFile=%inputFile%-TMP.txt"
>"%outputFile%" (
For /f "delims=" %%* in (
'find.exe /n /v ""^<"%inputFile%"'
) Do (
Call:GoParse "''%%*"
(echo\!WriteLine!)
)
)
Move /Y "%outputFile%" "%INPUT_VIDEO%"
Del "%inputFile%"
:end ----------
goto:eof
:GoParse lines
(Set /a i = %i% +1)&(Set Line=%1)
(Set Line=!Line:''[%i%]=!)&(Set "WriteLine=")
(Set Line=%Line:FPS 50 / 2=FPS 24000 / 1001%)
(Set WriteLine=%Line:~1,-1%)
goto:eof
(Set Line=%Line:FPS 50 / 2=FPS %NOMINATOR% / %DENOMINATOR%%) |
|
#5
|
|||||||||
|
|||||||||
|
Quote:
Code:
Del "%inputFile%" pause :end |
|
#6
|
||||||||||
|
||||||||||
|
When you insert a Pause in the batch you still won't be able to see the results on screen because the output is redirected to the file.
To show output on screen and WRITE it to a file the same time you should insert a TEE routine in the batch. However, it would also be possible to Echo %WriteLine% simply twice - one it will be redirected for APPENDING to the file and one time for showing the results on the screen. Code:
@echo off & setlocal enabledelayedexpansion
Set "inputFile=C:\test\test.txt"
Set "outputFile=%inputFile%-TMP.txt"
Set "NOMINATOR=24000"
Set "DENOMINATOR=1001"
If exist "%outputFile%" del "%outputFile%"
For /f "delims=" %%* in (
'find.exe /n /v ""^<"%inputFile%"'
) Do (
>>"%outputFile%" Call:GoParse "''%%*"
(echo\!WriteLine!)
)
::# replace original file (! remove 'rem' !)
rem Move /Y "%outputFile%" "%inputFile%"
echo\&pause
:end ----------
goto:eof
:GoParse lines
(Set /a i = %i% +1)&(Set Line=%1)
(Set Line=!Line:''[%i%]=!)&(Set "WriteLine=")
:: string substitution (is case-insensitive!)
:: http://www.robvanderwoude.com/ntset.php#StrSubst
(Set Line=!Line:FPS 50 / 2=FPS %NOMINATOR% / %DENOMINATOR%!)
(Set WriteLine=%Line:~1,-1%)
(echo\!WriteLine!)
goto:eof
__________________
This posting is provided "AS IS" with no warranties, and confers no rights. __________________ ** Remember to give credit where credit's due ** and leave Reputation Points for meaningful posts |
|
#7
|
||||||||
|
||||||||
|
for text processing, please get a good text processing tool, such as sed or gawk for windows. eg
Code:
C:\test>more file.txt DGAVCIndexFile7 C:\Personal\Videos\87943231_1280x532_23.976.h264 C:\Program Files\DGAVCIndex\ STREAM 0 FO 2 YUVRGB 1 LUMFILT 0 0 CLIP 0 0 0 0 RANGE 0 117586579 AUDIO --------Bulk of the file removed here since it takes up a lot of space-------- SIZ 1280 x 532 FPS 50 / 2 CODED 3339 PLAYBACK 3339 C:\test>sed -i.bak "s/FPS *50 *\/ *2/FPS 24000 \/ 1001/" file.txt C:\test>more file.txt DGAVCIndexFile7 C:\Personal\Videos\87943231_1280x532_23.976.h264 C:\Program Files\DGAVCIndex\ STREAM 0 FO 2 YUVRGB 1 LUMFILT 0 0 CLIP 0 0 0 0 RANGE 0 117586579 AUDIO --------Bulk of the file removed here since it takes up a lot of space-------- SIZ 1280 x 532 FPS 24000 / 1001 CODED 3339 PLAYBACK 3339 C:\test> |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| .cmd replace mutliple characters | diekstra | General Scripting | 7 | 31st May 2008 23:05 |
| Windows text file parser; I need to compare two text files... how? | Nonapeptide | Misc | 10 | 30th April 2008 14:21 |
| Cmd Key Bindings - Ctrl-D to quit cmd? | humbletech99 | Windows 2000 Pro, XP Pro | 0 | 28th April 2008 11:10 |
| google search text box | alitoday | Misc | 4 | 15th January 2006 21:21 |
| text in google search | alitoday | Misc | 3 | 29th December 2004 04:47 |