I'm looking at having a separate file (e.g. bash_aliases) to hold variables that represent colour characters e.g:
Black="\[\033[0;30m\]" # Black
Putting this in my rc/profile files would make it look horrendous; is there some way I can simply read in these variables from another file?
You can evaluate external shell script commands in current shell using source command, or .:
source .color_rc
or
. .color_rc
in your .bashrc
Related
I have a master .slx where I have hundreds of models inside and I want to know if some variables are used or not.
I have used grep and findstr in the directory where my whole project is but that is only showing me the files where the variable is declared (.m file) but not where the actual variable is used in the model.
I have tried opening the .slx and do a ctrl+f and yeah, it is telling me where the variable is used but this is not convenient since I have around 100 variables that I need to search for.
Is there a systematically way to do the search throughout the models?
I saved my command line by first clicking on it and pressing ctrl+s and MATLAB saves a .mat file.
Now I want to open it in a text form in order to remember what I did in my command line the other day.
Is there a way to do that?
Saving a .mat file from the command window saves all of the variables that currently exist within your workspace within a binary .mat file. There is no information about the commands that were used to generate these variables in this file format therefore it cannot be automatically extracted from another program.
If you need to get information about what commands were run, you can look at your command history to see this. If you need to programmatically access this file you can look in MATLAB's preference directory for the file named history.m or history.xml on newer versions.
type(fullfile(prefdir, 'history.m'))
If you need to keep track of what commands you run in the future, you can use diary at the top of your script or beginning of your session to log all commands and associated command line output to a plain-text log file which would then be accessible to other programs.
diary('mylogfile.txt')
In ipython, I know I can save aliases.
Is there similar way to save my own function, so that in is available next time I run ipython ?
lets say I have function:
def x(a,b):
print a+b
I tried using the %store command:
%store x
stored x (function)
But next time I start ipython it says:
name 'x' is not defined
I don't know if the exact feature you are asking exists in ipython.
What I do to handle this common case is to copy the functions in a .py file saved in the same folder as the notebook. Then, you can import the functions at the beginning of the notebook.
In this way, several notebooks can use the functions that are defined only once. It is also easy to distribute the notebook and the .py file together (for collaborating or moving to different machine).
Alternatively you can put the functions in a ipython notebook. From a notebook, you can "import" another notebook like it was a .py file, just use a notebook file name without spaces or '-'.
This approach is very similar to the .py file. The advantage is that you can add a more "rich" description of the functions (links, images, math formulas, etc...). The drawback is that you can't
seamlessly import the functions in another python script.
The only drawback of these approaches is that if you have a complex structure of folders and subfolders containing notebooks, you need to copy (or link) the .py file in each subfolder. To avoid that,
you can put your .py file in a single location and use absolute imports in the notebooks.
When you start ipython, you have to restore saved variables, aliases and functions using:
%store -r
There is however a chance this will not work, as there is apparently a bug
I'm using MATLAB under Windows, and trying to display (dump) the contents of a text file in the command shell. It seems like overkill to open a small file in the editor, or to load the file to use disp.
Use type and specify the explicit file name (including the extension), for instance:
type('myfile.txt')
As well as type, there's also dbtype which lets you pick a start and end range to print, and shows line numbers - handy for listing source files.
I have a program who's generating some data in registry.
I save it with "reg export HKCU\Software\ProgramName\Data data.reg" (Unicode format).
I need to take it to other computer and import it there so the program from that computer could use the data.
But I have to remove some text lines from data.reg. The text lines are easy to find because they contain some strings (for example paths to exe and dlls, specific program settings like "name1=value1", "name2=value2",...).
Now I'm doing this manually (using Wordpad) every few days but maybe there is another way...
Oh and I can't install other programs on these computers (the access is restricted) so I have to use batch/cmd files.
What I tried so far:
- redirecting the export to "con" but is visual only not in a variable;
- using "for /F ..." but this works only with ANSI and removes blank lines.
The lines must be removed before importing because the settings of the program from the first computer must not be loaded into the registry keys of the program from the second computer.
Can somebody please help me...?
Thank you.
Use this code to loop the file contents line by line
FOR /F %z IN (yourfile.reg) DO ...
Then use conditionals to determine if this line is one you want to keep
IF (%z)==[put your key string here]
If so (or if not), then write that variable to the target file
#echo %z >> output.reg
You can replace the filenames with command line arguments, use %1, %2, etc.
All together, then:
FOR /F %z IN (%1) DO IF NOT (%z)==[skip this line] #echo %z >> %2
Since you didn't give some critical details, I am making some assumptions here. Further reading can be found at this excellent resource: http://www.robvanderwoude.com/batchfiles.php
An example would be nice, but could you use reg delete to delete the keys/values you want after importing your .reg file?