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.
Related
I basiclly need to remove some text from file name and there is multiple file. I think I made a mistake. File name was baddly changed eg. 1.9.1.json --> 1form.9.1.json. I expected 1.9.1form.json. Here is code that I tried:
ren *.json ???form.*
I am looking for a code to undo this, and fix of my code that I tried.
Please don't explane it since I am python coder and I even have no idea to print Hello world in batch.
Note: I can't change it one by one since there is fifty files.
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
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 aware of the package touch, which does exactly this. However after installing and using the package, Stata 12 SE (Mac 10.9.5) says:
The touch command has been deprecated.
Is there an alternative? I need this to initialize a blank result file, so that I can append my regression result in a loop without caring whether I'm in the first iteration or not.
NEW ANSWER
Use one of the following in your do file to create the blank xls file "newfile.xls":
shell echo /dev/null > newfile.xls
which will overwrite existing files of the same name. To create a new blank file of that name:
shell touch newfile.xls
would also work. However if a file of the same name exists, touch would only change the modification and access times.
OLD ANSWER
The following will save an empty Stata data file "newdata.dta". Substitute your own name.
save newdata, emptyok
With Mac, you can just use the native touch: !touch filename.xls,
or
!> empty_results.txt, if you want to over-write an existing file or create it if it does not exist.
I am trying to make a script in bash that requires the removal of the the file extension from a file name, like the following
original: something.zip
removed version: something
And I was thinking I could use cut for this, but I am worried that a situation could arise where there might be a file name that has more than one period, etc, something similar to the following
something.v2.zip
having said that, I was wondering if anyone had any recommendations as to what I could do to just remove the last period and the text after it from a line of text/filename? any help would be appreciated, thanks!
f=file.zip
echo "${f%.zip}"
file
The '%' is a parameter modifier, it means, delete from the right side of the value of the variable whatever is after the '%' char, in this case, the string .zip. You can make this more general to remove any trailing extension, by using a wild card like
echo "${f%.*}"
file
If you want to remove the from the last period to the end, try this:
$ f=some.thing.zip
$ echo "${f%.*}"
some.thing