Unpacking Assignment in Python
The unpacking assignment assigns elements of a tuple/list to variables at once.
Runtime Paths in Python
__file__ is the path of the Python script.
Note that if you make a sybolic link to a Python script and run the symbolic link,
then __file__ is the path of the symbolic link.
Of course, you can use os.path.realpath to get real path of files.
pathlib.Path …
Select Columns from Structured Text Files
Python pandas
My first choice is pandas in Python. However, below are some tools for quick and dirty solutions.
q
q -t -H 'select c1, c3 from file.txt'
cut
cut -d\t -f1,3 file.txt
awk
awk -F'\t' '{print $1 "\t" $3}' file.tsv
Note: neither cut …
Get Group Names on Linux/Unix
Linux
-
Get information of the
staffgroup.$ getent group staff staff:x:20: -
Get group ID of the
staffgroup.$ getent group staff | cut -d: -f3 20
Mac
-
Get information of the
staffgroup.$ dscl . -read /Groups/staff -
Get group ID of the
staffgroup.$ dscl . -read /Groups/staff | awk …
List Running Jupyter Notebook Servers
You can list running Jupyter Notebook servers using the following command.
jupyter notebook list
It works well most of the time. However, if the servers are launched using the root account (e.g., in a Docker container), you might encounter issues. In this case, a better alternative is to list …