View Full Version : What is the quickest way to add a line in multiple avs files?
I thought the audience here might be best qualified to help me find an answer to this question. I seem to remember a dos utility that did this sort of thing.
Basically I want to add a filter line at the same location in the multiple avs files (might be 50-75 of these). They are named in a numerical order so a wildcard would work for the file names.
An example might be if the original is:
mpeg2source("D:\MyD2V.D2V")
BilinearResize(352,480)
ConvertToYUY2()
and I wanted to add undot() to them all:
mpeg2source("D:\MyD2V.D2V")
undot().whatever.whatever
BilinearResize(352,480)
ConvertToYUY2()
Any suggestions? I would appreciate them.
Mug Funky
4th May 2004, 14:52
hmm... usually this is best done with a bit of programming. last i did this sort of thing was with macromedia director (AAAAAARRGH! the PAIN!), so i'm not much help here...
how many scripts do you need to change? i find with something like an episodic DVD, there's only an average of 5 scripts needed, so it doesn't take much of my time to edit them all with a ctrl+v.
i recommend something like TextPad - it keeps a list of open files, so you just need to open them all up, then go "click, ctrl+v, click, ctrl+v, click, ctrl+v, click, ctrl+v" until you're done.
it would be handy to have a little app to do this... i wonder if one exists?
[edit]
ah... 50-75 scripts? hmm. i'd say overall that it'd be quicker using textpad than writing a whole program. unless this becomes something you have to do often.
A C program for this would be less than 15 minutes.
A C program for this would be less than 15 minutes Perhaps somebody with that skill will consider doing it. I think it would be useful for some, especially if it were an easy thing for someone to do.
Malcolm
4th May 2004, 15:53
there are some Texteditors that can do Search&Replace in multiple Files. A whole folder for example or via wildcards (*.avs).
there are also some IDEs which can do that.
Or do you ask for a commandline utility? do you have to do this once or do you try to find a solution to do this repeatedly in the future?
g*
Malcolm
Mug Funky
4th May 2004, 16:16
A C program for this would be less than 15 minutes.
well, if you know C it does... i have a hopeless memory, and even languages i'm familiar with (mostly multimedia related ones, crap like Lingo and ActionScript) i have to work with the help files open.
Yes, it is something I expect to do repeatedly and I have some hope of slightly automating it, not completely of course, just trying to make it fairly brain-dead. The line I would actually insert would be an import statement that would import an avs with a set of filters I like to use. A key point is it needs to be able to insert location specific (directly under the mpeg2source line). I'm not suggesting any intelligence for dealing with a moving target, the mpeg2source line will always be on line X of the script group.
albertgasset
4th May 2004, 17:53
This won't be helpful if you don't use Linux (or any OS with a bash shell), but this is a possible solution that works in a Linux shell:
Create a file named PATCHFILE with conent (replace 4 and 5 in "4a5" with the appropriate line numbers):
4a5
> This line will be added after line 4 of each file, and will become line 5
and then execute this command in a shell:
for file in DIR/*; do patch -i PATCHFILE $file; done
DIR is the folder with all the files where the line has to be added.
I'm sure there are simpler ways of doing this :)
Albert
albertgasset, just plain old XP here and nobody too brilliant behind the keyboard. Well, out of town for a day, so I will not be able to respond till late tomorrow. Thanks for the replies, all.
Here's a batch file that will do the job. Note, requires WinNT/2000/XP. Also note that empty and commentary lines (starting with #) are not counted.
@echo off
setlocal enabledelayedexpansion
Rem ===================================================================
Rem Batch for inserting a line into every AVS file in a specific
Rem directory
Rem
Rem Usage: insline [directory] [text] [line number]
Rem
Rem Make sure to use quotes around directory and text.
Rem
Rem Example: insline "d:\rebuild\d2vavs" "undot().deen()" 2
Rem
Rem Recursively scans directory d:\rebuild\d2vavs for .AVS
Rem files and inserts undot().deen() at line number 2 into
Rem every .AVS. -1 for line number appends at end of file.
Rem ===================================================================
for /R %%F in ("%~1\*.avs") do (
set line=0
if "%~3" == "-1" (
echo %~2>>"%%F"
) else (
if exist "%%~dpnF.$$$" del "%%~dpnF.$$$"
for /F "usebackq delims=" %%I in ("%%F") do for /F "tokens=1 delims= " %%J in ("%%I") do (
set char=%%J
set char=!char:~0,1!
if not "!char!" == "#" (
set /A "line += 1"
if "!line!" == "%~3" echo %~2>>"%%~dpnF.$$$"
)
echo %%I>>"%%~dpnF.$$$"
)
del "%%F"
ren "%%~dpnF.$$$" "%%~nxF"
)
)
Was starting to head out the door and saw this. Wow! RB, this was extremely kind of you to do. I think quite a few will benefit. I did try it quickly with the commandline:
insline.bat "D:\WUTemp\D2VAVS" "Undot().Deen()" 3
and I got:
".Deen( was unexpected at this time." Quotes are mine of course. Inside is an exact copy & Paste from command.
stax76
5th May 2004, 00:50
the easiest way to do such things is to use a text editor with windows shell support to open all files at once, support for multible documents to apply a search and replace action on all files at once and support for regular expressions to search and replace patterns. Regular expressions is a extremely powerful tool originated in the Unix world to deal with text. It works like this with NoteTab Light, it's Freeware of course.
Open your text files with the windows shell, for instance select all files with the mouse or the keyboard pressing shift and drag 'em on the opened program or on the executable or on a link to the executable or press enter if the program is the default program. For each file there should be a tab now
Now open the search and replace dialog, check "All Documents", check "Regular Expressions" and set the focus to "All"
enter now the following search patter:
{mpeg2source\(".+"\)}
now enter the replace patter:
\1\nundot\(\).whatever.whatever
it puts your undot line under every mpeg2source line in all documents. It takes time to learn regular expressions, for programming it's a very important thing often needed several times a day, be it for editing the source code or used by the program self to parse text
Video Dude
5th May 2004, 01:14
DDogg, sounds like you had the same idea I had to modify DVD Rebuilder's AVISynth scripts.
There is a program called "Simpli-File Find Replace and Insert". Its shareware but they offer a free 15 day trial.
It does everything you want. It does directory batch processing. You simply enter the line of text you want to enter and specify the line number and then hit the process button.
Or you could use the search and replace feature (if all your avs files refer to the same d2v file):
Search for:
mpeg2source("D:\MyD2V.D2V")
BilinearResize(352,480)
ConvertToYUY2()
Replace with:
mpeg2source("D:\MyD2V.D2V")
undot().whatever.whatever
BilinearResize(352,480)
ConvertToYUY2()
You can find it at http://www.batchtech.com
Originally posted by DDogg
".Deen( was unexpected at this time." Quotes are mine of course. Inside is an exact copy & Paste from command.
LOL, should make sure my own examples work :) Sorry, here's the corrected version (actually it's an annoying quirk in the NT batch processor that I seem to constantly forget about)
@echo off
setlocal enabledelayedexpansion
Rem ===================================================================
Rem Batch for inserting a line into every AVS file in a specific
Rem directory
Rem
Rem Usage: insline [directory] [text] [line number]
Rem
Rem Make sure to use quotes around directory and text.
Rem
Rem Example: insline "d:\rebuild\d2vavs" "undot().deen()" 2
Rem
Rem Recursively scans directory d:\rebuild\d2vavs for .AVS
Rem files and inserts undot().deen() at line number 2 into
Rem every .AVS. -1 for line number appends at end of file.
Rem ===================================================================
set text=%~2
for /R %%F in ("%~1\*.avs") do (
set line=0
if "%~3" == "-1" (
echo !text!>>"%%F"
) else (
if exist "%%~dpnF.$$$" del "%%~dpnF.$$$"
for /F "usebackq delims=" %%I in ("%%F") do for /F "tokens=1 delims= " %%J in ("%%I") do (
set char=%%J
set char=!char:~0,1!
if not "!char!" == "#" (
set /A "line += 1"
if "!line!" == "%~3" echo !text!>>"%%~dpnF.$$$"
)
echo %%I>>"%%~dpnF.$$$"
)
del "%%F"
ren "%%~dpnF.$$$" "%%~nxF"
)
)
Eldritch
5th May 2004, 08:33
Ok, after having lurked here for far more than a year now, I have finally found a thread to reply to.
A solution that works and that is very simple (I've tried it myself) is using the editor UltraEdit. It can do search & replace in multiple files. The dialog is somewhat hidden in the Edit-Menu but it's there.
There is a 30-day uncrippled trial version of UltraEdit. If you're looking for a completely free editor or similar tool look at www.tinyapps.org
@All, thanks for the replies. I'm kinda hoping I can get RB's batch file to work. I can see from your posts that advanced text editors will do what I want to do. Thanks for those suggestions as I am not at all familiar with them.
@RB, are you using XP? I ask because the error is fixed, but no changes are being done to the avs files. This is when using 3 as line number or -1. I am wondering if my XP command line supports all the things your script needs. Thanks again for taking your time to do this batch. It is just what I'm looking for.
actionman133
5th May 2004, 12:38
there is an scripting solution that i have used for the last couple months, precisely because of that.
i have ripped dvds on my computer, but being the quality freak i am, i didnt want to recompress; in fact i wanted to improve the quality beyond those of commercial dvd players. of course, the code was changing every 20 minutes, and it was tiresome to say the least.
i ended up creating an information script and a core script. the information script would simply collect the details, and pass it to the core. so any changes to the core affected all scripts using at once. i'll show you what i did by example (extract):
File: "Superbrawl.avs"
VideoName = "Superbrawl" # Name of video D2V file
AudioDelay = -0.016 # Delay of audio as dictated by DVD Decrypter
Folder = "C:\Videos\DVD's\The Matrix Revolutions" # Location
Speed = 24 # New framerate (I use PAL sources)
Import ("C:\Videos\DVD's\DVD AVS's\Core.avs")
the 'Import' line appends the following core script to the bottom.
File: "Core.avs"
SetWorkingDir (Folder)
MPEG2Source (VideoName + ".d2v")
AudioDub(WAVSource (VideoName + ".wav").DelayAudio (AudioDelay)
ConvertToYUY2 ()
LanczosResize (1024, 576).Sharpen (0.78)
AssumeFPS (Speed, True)
ResampleAudio (48000)
now this is a simplified example, but the point's the same. if create a file to store all necessary information, and then import a core to do all the processing, any changes you make to the core, will apply to all of the scripts.
did you get that? :confused: anyone?
Malcolm
5th May 2004, 12:42
i don't know if this helps here, but i find your way of working very clever and interesting! i think i'll adopt it for my scripts!
Greetings,
Malcolm
Originally posted by DDogg
@RB, are you using XP? I ask because the error is fixed, but no changes are being done to the avs files. This is when using 3 as line number or -1.
Yes, using XP, it's working just fine here. It is the default, but make sure that in both HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor and HKEY_CURRENT_USER\Software\Microsoft\Command Processor the "EnableExtensions" DWORD value is set to 1.
stax76
5th May 2004, 15:13
I'll try to explain the regular expression
mpeg2source("any file")
because parenthesis "(" and ")" is part of the regular expression language a backslash has to be put in front of the parenthesis so the regualr expression engine knows the actual character is meant, so the expresion must be written as this:
mpeg2source\("any file"\)
the file name can be any character one or more times, any character is . and one or more times is + so the expression is now this:
mpeg2source\(".+"\)
this expression is required in the replace pattern, if we put the expression in curly braces we can in the replace pattern refer to it with \1, so the search regular expression is now finished:
{mpeg2source\(".+"\)}
the replace pattern consist of \1 which is everything between the curly braces in the search pattern plus \n which is a new line plus the Undot line
\1\nundot\(\).whatever.whatever
quite simple isn't it :)
trolltuning
5th May 2004, 15:29
@@ actionman133
What a great solution.
The import command is really hidden in the AviSynth documentation and I'm sure I'm not the only one who missed the importance of it.
As I often want to change scripts so as to make either VCD, SVCD or DVD this is really useful.
Does importing from another script make any difference in performance speed?
RB, yes those reg setting are both set to 1. I'm trying to figure this out, but I can't follow the batch enough to debug it.
I did notice something I thought should be mentioned. If I execute "insline" with no parameters in the root of my D harddrive, insline does rewrite every avs in every directory. I can see the timestamps all change. I don't know if this is a feature or something else :)
The command line used from the root of D where I have insline.bat is:
insline "d:\WUTemp\D2VAVS" "Undot().Deen()" 3
Timestanps do not change so I wonder if I just am not getting the command correctly? I also tried:
insline "d:\WUTemp\D2VAVS\" "Undot().Deen()" 3
Any suggestions on where to place a debugging statement?
OK, found the problem. This should be finally working :devil: It wasn't failing here because I only tested with relative paths, e.g. 'insline "somedir\avsdir" ...'. It failed with full path names though, stupid syntax error on my part. I also changed it so that it doesn't do anything unless all command line parameters are present.
@echo off
setlocal enabledelayedexpansion
Rem ===================================================================
Rem Batch for inserting a line into every AVS file in a specific
Rem directory
Rem
Rem Usage: insline [directory] [text] [line number]
Rem
Rem Make sure to use quotes around directory and text.
Rem
Rem Example: insline "d:\rebuild\d2vavs" "undot().deen()" 2
Rem
Rem Recursively scans directory d:\rebuild\d2vavs for .AVS
Rem files and inserts undot().deen() at line number 2 into
Rem every .AVS. -1 for line number appends at end of file.
Rem ===================================================================
if "%~1" == "" goto :EOF
if "%~2" == "" goto :EOF
if "%~3" == "" goto :EOF
if not exist "%~1" goto :EOF
set text=%~2
for /R "%~1" %%F in (*.avs) do (
set line=0
if "%~3" == "-1" (
echo !text!>>"%%F"
) else (
if exist "%%~dpnF.$$$" del "%%~dpnF.$$$"
for /F "usebackq delims=" %%I in ("%%F") do for /F "tokens=1 delims= " %%J in ("%%I") do (
set char=%%J
set char=!char:~0,1!
if not "!char!" == "#" (
set /A "line += 1"
if "!line!" == "%~3" echo !text!>>"%%~dpnF.$$$"
)
echo %%I>>"%%~dpnF.$$$"
)
del "%%F"
ren "%%~dpnF.$$$" "%%~nxF"
)
)
Oh YEAH! Working like a champ now. Freaking awesome, and it is very fast. Damn nice of you to do this for us 'DOS challenged' folks.
Btw, I think you are way too hard on yourself. "RB" + "Stupid" are mutually exclusive terms in my book. :) (big slurp, slurp) :-D
/Add: sweet, it also doe not choke on quotes within quotes so the command:
insline "d:\yourdir" "import("d:\yourdir\myfilters.avs")" 3
works perfectly. It might be a good idea to backup your dir before using this batch file until you get used to it.
Video Dude
5th May 2004, 21:03
Thanks for the script RB. Good work!
actionman133
5th May 2004, 22:08
Originally posted by trolltuning
@@ actionman133
What a great solution.
The import command is really hidden in the AviSynth documentation and I'm sure I'm not the only one who missed the importance of it.
As I often want to change scripts so as to make either VCD, SVCD or DVD this is really useful.
Does importing from another script make any difference in performance speed?
i think the import line will slow down the initialisation when the video is opened (about 2 seconds on my p4, but theres more to it than ive shown), however after the script is opened in media player or vdub, whatever, it plays back at the normal speed. of course, im no programmer, and my computer might be fast enough to not notice any real-time speed hits. maybe one of the developers might know.
on this board, but I'll also add mine to the fray, the suggestion I always suggest for any type of repeated task in XP -- autoit.
http://www.hiddensoft.com/cgi-bin/countdown.pl?AutoIt/AutoIt.exe
1. download the above exe file
2. install it
3. open notepad
4. paste the below script into notepad + make any changes you see fit
5. save the file to whatever.aut <-"aut" is the extension to run it using autoit
; ------------------------------------------
; ----- user settings (case sensitive) -----
; ------------------------------------------
SetEnv, PATH, C:\\
SetEnv, FILENAME, ddog
SetEnv, FIRST, 1
SetEnv, LAST, 50
START:
Run, notepad.exe %PATH%%FILENAME%%FIRST%.avs
WinWaitActive, %FILENAME%
Send, {DOWN 2}{ENTER}{UP}
; ----------------------------------------------
; ----- put your line to be inserted below -----
; ----------------------------------------------
Send, undot().whatever.whatever
Send, ^S
Send, {ALT}{UP 2}{ENTER}
WinWaitActive, Notepad
Send, {ENTER}
StringRight, NUMBER, EPISODE, 2
IfEqual, LAST, %FIRST%, Goto, END
EnvAdd, FIRST, 1
Goto, START
END:
Exit
I set it up so you need to name your avs files as such, but you can change this to whatever you want in the script. It's case sensitive though:
ddog1.avs
ddog2.avs
---
ddog20.avs
etc
You need to place the avs files in the default C:\ root. You can change this too if you want.
And depending on how many avs files you got, just change the variable LAST from "50" to whatever you need. I tested it out and it works like a charm.
LB, thanks for taking the time to do this. I've always wanted to play around with autoit. Having a purpose script like this as an example is helpful and may provide a good way for me to try to learn more about it.
Peter1234
9th October 2005, 10:18
@RB:
Fantastic batch file. I have a DOS book but it doesn't have most of what you are doing in it. Can you please suggest a reference book that explains how to write programs like your batch file.
Pookie
9th October 2005, 10:40
http://www.amazon.com/exec/obidos/tg/detail/-/1578700477/002-9137109-4171217?v=glance
http://www.computerhope.com/batch.htm
http://www.student.oulu.fi/~vtatila/batch_tutorial.html
http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/win32scripting/win32scripting.html
http://cwashington.netreach.net/depo/?topic=repository&scripttype=command
Peter1234
9th October 2005, 10:54
@Pookie:
Thanks.
stax76
9th October 2005, 12:27
The old win command shell is prolly the worst shell. It's good to know at least the basics but I would rather try to use something easier and more powerful. Fortunately there are some alternatives e.g. Monad, the new windows command shell, it's extremely powerful, besides shell like commands it's supports also COM and .NET scripting!
http://www.microsoft.com/downloads/details.aspx?FamilyID=8a3c71d1-18e5-49d7-952a-c55d694ecee3&DisplayLang=en
http://www.microsoft.com/downloads/details.aspx?familyid=2AC59B30-5A44-4782-B0B7-79FE2EFD1280&displaylang=en
http://www.microsoft.com/downloads/details.aspx?familyid=7ABD8C8F-287E-4C7E-9A4A-A4ECFF40FC8E&displaylang=en
or maybe bash in cygwin, never tried this:
http://www.cygwin.com/
or maybe the windows scripting host using either JavaScript or VBScript:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/scriptinga.asp
Jeremy Duncan
8th May 2011, 12:14
OK, found the problem. This should be finally working :devil: It wasn't failing here because I only tested with relative paths, e.g. 'insline "somedir\avsdir" ...'. It failed with full path names though, stupid syntax error on my part. I also changed it so that it doesn't do anything unless all command line parameters are present.
@echo off
setlocal enabledelayedexpansion
Rem ===================================================================
Rem Batch for inserting a line into every AVS file in a specific
Rem directory
Rem
Rem Usage: insline [directory] [text] [line number]
Rem
Rem Make sure to use quotes around directory and text.
Rem
Rem Example: insline "d:\rebuild\d2vavs" "undot().deen()" 2
Rem
Rem Recursively scans directory d:\rebuild\d2vavs for .AVS
Rem files and inserts undot().deen() at line number 2 into
Rem every .AVS. -1 for line number appends at end of file.
Rem ===================================================================
if "%~1" == "" goto :EOF
if "%~2" == "" goto :EOF
if "%~3" == "" goto :EOF
if not exist "%~1" goto :EOF
set text=%~2
for /R "%~1" %%F in (*.avs) do (
set line=0
if "%~3" == "-1" (
echo !text!>>"%%F"
) else (
if exist "%%~dpnF.$$$" del "%%~dpnF.$$$"
for /F "usebackq delims=" %%I in ("%%F") do for /F "tokens=1 delims= " %%J in ("%%I") do (
set char=%%J
set char=!char:~0,1!
if not "!char!" == "#" (
set /A "line += 1"
if "!line!" == "%~3" echo !text!>>"%%~dpnF.$$$"
)
echo %%I>>"%%~dpnF.$$$"
)
del "%%F"
ren "%%~dpnF.$$$" "%%~nxF"
)
)
I tried to run this bat file and don't know how. Where do I type the directory name, in cmd prompt or in the bat file, where in the bat file?
mastrboy
8th May 2011, 20:29
notepad++ can search/replace in multiple open files at once and has support for regexp if needed.
Jeremy Duncan
13th May 2011, 09:58
Here is what I want to do but am still learning C so it's a ways off.
In some online websites you have to fill in some data, like your age or something. And when you fill in a box and there are three boxes you have to click the next box to fill it in. But in some website you can just keep typing and it jumps to the next box automatically.
With that kind of automation I want to paste a list of 3 or 4 trims into the forms box, then this is saved as a file automatically. And since I pasted a list of trim this keeps filling in the box and saving the file. All I have to do is paste the trim list into the forms box Once.
Groucho2004
13th May 2011, 11:37
Here is what I want to do but am still learning C so it's a ways off.
In some online websites you have to fill in some data, like your age or something. And when you fill in a box and there are three boxes you have to click the next box to fill it in. But in some website you can just keep typing and it jumps to the next box automatically.
With that kind of automation I want to paste a list of 3 or 4 trims into the forms box, then this is saved as a file automatically. And since I pasted a list of trim this keeps filling in the box and saving the file. All I have to do is paste the trim list into the forms box Once.
Apart from digging up a thread that has been decomposing for 6 years you have given the phrase "off topic" a new meaning.
How is auto-filling web forms related to this topic? I guess we'll never know.
Wilbert
13th May 2011, 19:02
@Jemery, stop posting this nonsense. You should know better. If you have something worthwhile to say which is on topic, then you are free to do so. Otherwise don't. This is not a chitchat forum.
DarkT
15th May 2011, 14:50
Mmmm, guys... Dont be too hard on him, I actually needed jsut such a thing, and searched for it and made threads, but on other forums. I gave up eventually, and now got a SUPER nice surprise ;)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.