I am using a program which checks a config file at every start with the given settings, I am editing a specific line inside the config file very often to find out which option is the best. I wanna add a option to my batch script which asks me for a input that I type inside the command prompt and replaces it with the current text on that line inside the file. The line inside the config file that I want to replace is called max_items: 2. I basically just wanna replace the number everytime I chose the option inside my batch script. I already heard of a text command utility called FART but I don't know if it can really help me with the script that I wanna add to my batch file bc it should ask for a input and replace it with that input. I hope someone has a Idea and can help me out
Related
I'm trying to make an batch file that will copy the contents of a .cfg file into another .cfg file. The problem I'm having is that I want the contents of the first file to be placed at specific lines of the destination file, for example, placing the contents between line 300 and 343 and overwriting the original content within those lines.
Any way of doing this?
If there isn't a way to detect specific lines maybe there is a way to detect a specific string, like an ID?
If you are allowed to use 3rd party tools in your environment you can use a regex CLI tool to find and then replace the lines / values you need. The tool can be called using batch scripts.
Example Tools from another question:
https://superuser.com/questions/339118/regex-replace-from-command-line
I need to extract the object name from a sql text file. All of my sql files have as their 1st line "CREATE some type [schema name].[object name]. Sometimes the brackets are there, other times not. In either case, I need to be able to discern the object name affected so I can determine if it actually exists before updating the server with the new changes. I need to do this from a Windows 7 command line batch file. Not powershell, please.
Doing this in a batch file is a bit like working without your hands tied behind your back, but if you insist, I would suggest the following:
Get the first line of the file (you said in the comments that you can already do this).
Split the line on spaces and get the x-th value.
Split the resulting value on the dot.
Strip the backets from the value.
Voila. It won't be easy, it won't be readable, but it will do what you need and it will be a Windows cmd batch file.
I'm using a program called lewice that runs in a dos window.
When you run the program it requires 'user input' to give a file name for the input files.
Is there anyway I can get a batch file to send the commands to the dos window so the batch file can by default use file name x?
Thanks
Not sure if that's what you want but maybe lewice can use inputs parameters, you just have to create a shortcut and add options:
https://superuser.com/questions/29569/how-to-add-command-line-options-to-shortcut
It might get trickier if the path to the file has spaces.
I am trying to make a batch file that will copy the contents of one file (with problem characters) that sends an email into another file (also vbs) so as to then run it and send a customizable email (customized by various batch things, my program needs to use batch) So I want to use this command:
type mailersample.vbs>> mailerfinal.vbs
BUT I want to edit certain things. Would I need to go through a variable (problem characters), or would I use the set command, in which case, under which format?
I suppose my question in not that clear but let me try to explain it here.
Let's suppose I have opened a file named myfilename.java with the below content
public class test{
}
Now, what I want is to replace test with myfilename. Now to get the filename in vim I used :echo expand('%:r') which gave me myfilename.
Now, my question is how to do I use the above output and replace test with it and map it to a key for future use. What I need is may be something like:
:%s/test/above_output_from_command/g
You need to add \= to tell Vim you're trying to call a function:
:%s/test/\=expand('%:r')/g
See :help sub-replace-expression.
For my application, I ended up using a keybound macro (not sure what the VIM) name for this is) that did the edit I want and simply inserted the filename where I wanted it:
:nmap <F5> 0d$:put =expand('%:p:t')^M0ipackage ^[$a;^[
In my case, I wanted to insert the name of the containint directory instead of the file, so I used:
:nmap <F5> 0d$:put =expand('%:p:h:t')^M0ipackage ^[$a;^[
The 0d$ deletes the contents of the current line, :put =expand('%:p:t')^M inserts the filename, and the remaining commands edit the line around the command to produce something like
package containing_directory;
on the current line.