arr=() Create an empty array arr=(1 2 3) Initialize array ${arr[2]} Retrieve third element ${arr[@]} Retrieve all elements ${!arr[@]} Retrieve array indices ${#arr[@]} Calculate array size arr[0]=3 Overwrite 1st element arr+=(4) Append value(s) str=$(ls) Save ls output as a string arr=( $(ls) ) Save ls output as an array of files ${arr[@]:s:n} Retrieve n elements starting at index s
Bash array operations – short table.
Bash – using mailx command to parse subjects
Problem: It appears that the default mail -H appears to truncate the subject. Grep fails to find text pass the email address. Fix: Use Headline to format echo ‘f 1-$’ | mail -H -S headline=”%>%a%m %20f %16d %3l/%-5o %i%150S” | grep -i ANZ535 | wc -l Here is what the issue looks like [ec2-user@jibsheet data]$ echo ‘f 1-$’ | […]
How to attach and detach from container
Thoughts on attaching to Docker Container: Especially useful for Turnkey Linux docker containers. In some cases you need to exit the fence to continue to boot. Then ssh back in with root to set the password. When you attach like this – you can more or less think of this as the master console of the container. When first bootstrapping […]
Vim tips and links
Here are a few useful links about VIM editor. Good overview of some nifty feature. https://www.cs.oberlin.edu/~kuperman/help/vim/home.html .vimrc tutorial at linuxhint. Vimrc Tutorial
Numpy – array of strings.
Numpy supports strings and array of strings. It is fixed length. If you replace an array element with a longer string it truncates it to fit. Each python character is 4 bytes ( unicode ). So a 40 character element in the array is 160 bytes. See example from Notebook below.
Using awk with ‘ls -l’ linux command
Some creative ways to use awk with ls -l command. Find all files for a certain month: ls -l | awk ‘$6==”Sep”{print}’ Find all files with a size greater than: ls -l | awk ‘$5>1009{print}’ [user1@jibsheet data]$ ls -l | awk ‘$6==”Sep”{print}’ -rw-rw-r– 1 user1 datausr 54255 Sep 9 12:34 alex_Y2021_M09_D09_H12.txt -rw-r–r– 1 user1 datausr 54255 Sep 17 01:33 alex_Y2021_M09_D17_H01.txt […]
ls -l – sort files by number in file name or extention
Use sort. Use -n for numeric and -t for field separator. then k for the field. [user1@jibsheet ~]$ ll $HOME/tidal* -rw-rw-r– 1 user1 user1 545 Oct 13 10:02 /home/user1/tidal_out.txt -rw-rw-r– 1 user1 user1 545 Oct 13 10:02 /home/user1/tidal_out.txt.1 -rw-rw-r– 1 user1 user1 564 Oct 12 22:39 /home/user1/tidal_out.txt.10 -rw-rw-r– 1 user1 user1 546 Oct 13 08:02 /home/user1/tidal_out.txt.2 -rw-rw-r– 1 user1 […]
How to reset git repo to remote origin
git fetch origin —- fetch from origin git reset –hard origin/master — this is the real reset. git clean -f -d **** warning clean will remove all data and directories not tracked. **** so if you have data file or untracked data – it will be gone. **** Not really necessary to really sync the actual code. But it will […]
How to change permissions in git ( Windows )
here is a procedure to change permissions in Windows and or Linux. Of course, in Linux it picks it up when you add the file for commit git ls-tree HEAD – the first column is the permission in the index. You have to commit before the index is actually updated. C:\Users\jonallen\Documents\github\weather_obs>git ls-tree HEAD 100644 blob bc24e36afc3ccfa261f3f1bfd16de59c6059b72b KDCA.xml 100644 blob 5998e23e67758e0cf3681c079437f91c8ece445e […]
rpm – how to find packages based on size
rpm -qa –queryformat ‘%10{size} – %-25{name} \t %{version}\n’ | sort -n returns a list – biggest down at bottom ………. 27698421 – binutils 2.29.1 30080231 – vim-common 8.1.1602 30573277 – python-libs 2.7.18 35589262 – scipy 0.12.1 36808072 – gcc-c++ 7.3.1 39563592 – mariadb 10.2.38 42421327 – python3-libs 3.7.10 48556145 – gcc 7.3.1 49102448 – python2-botocore 1.18.6 84934333 – mariadb-server 10.2.38 […]