Deleting a File or Replacing a File when Outsheeting in Stata - shell

I open up a .txt file. Make some modifications to it. Then I'd like to outsheet it with the same name. To do this, I presume either I'd have to delete the file right before I outsheet it or replace the file in the outsheeting process. As a backup, I can manually delete the .txt execute the relevant code.
I'd like to do this via Stata, however. Is it possible to either:
1. Delete a .txt file within a Stata .doe--say with a shell command ?
2. Overwrite a .txt file in the outsheeting process ?
I am outsheeting as in:
outsheet v1 v2 using "file.txt", nolabel delim(",")
I run Stata in Windows on an XP machine.

Add the replace option anywhere after the comma.
You can can also shell out to the OS. Type "h shell" to see how.
Or just use rm/erase directly.

Related

Script for copying a folder somewhere using Git Bash

I want to copy a folder ~/Projects/LocalProject onto my server //VM-Server/ServerProject.
I know that I can use GitBash:
cp -r directory-name-1 directory-name-2
But what I'm curious about is, can I create a script to do that by double clicking that script, or adding it as a command to my GitBash, cause I will need that alot?
--Edit--
Tried nothing, as I don't know how to do that. Yes there are hidden files, I don't want them to be copied. There shouldn't be newer files on the destination. I need to manually run it, I thought that's clear as I mentioned the option to have a executable script / or a terminal command.
Option 1: Batch file
You don't even need git-bash; you can make a batch file in any text editor, name it copy to server.bat, and type in cp C:\Users\<Your username>\Projects\LocalProject \\VM-Server\ServerProject.
You can also make a .sh file for use in bash. The command is the same, just make note that Windows uses \, while bash uses / for directory tree
Option 2: Alias
Open your bash_profile file (it's in your git bash install location).
Add a line at the end of the file that says alias copyToServer = 'cp ~/Projects/LocalProject //VM-Server/ServerProject'. Then close git-bash, reopen it and use the command by typing copyToServer as a bash command. (It doesn't need to be named copyToServer)

How execute file from parent directory without changing directories

I'm an enthusiast of efficiency. I want to execute a file in a parent directory and would appreciate it if anyone knows of a slick way to do it.
I'm using Windows command line.
lets say i have a file: C:\Documents\text.txt
and my current directory is: C:\Documents\pycode
I would like to open the textfile without changing directories or writing entire filepath.
I tried "..\text.txt" but it doesn't work.
Just add quotes.
"../text.txt"
Or, you can try this:
notepad "../text.txt"

Use drag and drop function to select multiple files and process all

I need a way to select several files with check-boxes and drag them all to a batch-file icon. The first step in the script would be to be compressed them into a single zip file before proceeding to the next step. If possible, it would be useful to also end up with each in a separate zip of its own for storage.
I am not sure how to address the for:to commands to allow gathering all selected files into a single zip file in a script. The Windows 'sendto compressed zip' function works perfectly if I select all the files the copy and paste them to the Windows ZF filetype. But I don't know how to access it from within a batch.
Drag and drop multiple files
By default, if you drag a file onto a batch file it is the same as passing the filepath as a parameter. This can be accessed using %%1. Dragging multiple files would have a similar effect and be like calling test.bat file1.txt file2.txt file3.txt. Each "parameter" can be accessed using subsequent variables, %%1, %%2, %%3, etc, up to %%9.
Get more information here.
Zipping files
First you will need a utility that supports command line operations, such as 7-zip. Once you have the appropriate executable in your path, you will need to review the documentation on how to zip files from the command line. Instead of using the paths and filenames, you will use the variables mentioned above.
Here is some pseudo code:
zipfiles output.zip %%1 %%2 %%3 %%4 %%5
Notes
You will not be able to drop more than 9 files.
You may need to confirm that each variable exists. If you try to include %%9 in the zip command but you only dropped 8 files, you may get an error.

Saving SQL files into specific folders in Oracle

I am using Oracle 11g. When I open a new SQL file writing the command
ed filename.sql
A new file is created in my bin folder with the name as filename but, I want them to be in separate folders for my convenience. I am developing 3 application(well for my practice only). I want them to store in different folders for each project. I tried all of the following none of them worked please tell me how can I save the files into specific folders.
ed erp/logindetails.sql
ed 'erp/logindetails.sql'
ed "erp/logindetails.sql"
ed 'erp\logindetails.sql'
ed erp\logindetails.sql
These commands except where I used "" worked and opened the default text editor with the name afiedt.buf which I am getting when I enter only edit. No files are created with any of the above command.
You're giving EDIT a relative path to the file; since your current working directory seems to be the bin directory that the SQL*Plus directory is in (is this Windows, and are you running a shortcut that sets the working directory, maybe?) it will try to create a file like %ORACLE_HOME%\bin\erp\logindetails.sql, and you're unlikely to have created an erp directory there. Giving the full path to the directory will work:
edit c:\users\dibya\projects\erp\logindetails.sql
for example.
As noted in the documentation, EDIT will search for existing files, but that involves setting an environment variable - which you'd have to change as you move between the projects. You might find it easier to edit the files in the OS and just run them from SQL*Plus.
You might also be able to use separate shortcuts to launch SQL*Plus for each project, each setting the 'start in' directory to a project-specific location - then just edit logindetails.sql would be looking in the right place by default. Or, from a command prompt cd into the relevant project-specific directory and launch SQL*Plus from there, which is effectively what a shortcut would do.

Using sed to find a string in one file and replace with text in another file in Xcode

shell: /bin/tcsh
I'm attempting to search for a string in a Cocos2D tmx file and replace it with text from another file.
Before the touch commands in Run Script, I have the following:
sed -i '' 's{<tileset firstgid="1.*<layer name="background"{Resources/maps_sideScrolling/tileProperties.txt{g' Resources/maps_sideScrolling/ruinsItemCave2.tmx;
I'm fairly certain the file ruinsItemCave2.tmx is found, because if I change the file path I get an error when I build the project. As of now, ruinsItemCave2.tmx is not affected in any way.
Eventually I will want to change ruinsItemCave2 to a wildcard filename so it affects every file name, though I'm not sure how to write Resources/maps_sideScrolling/*.tmx the proper way.
I also know that without even writing a file path of tileProperties.txt, but just writing "test" does nothing to my ruinsItemCave2 file, so I can't even get that far as of now. Does it have to do with using tcsh?

Resources