Here is a list of useful scripting commands that I use very often:
Shell Scripts
- find . -type f -exec basename {} \; | sed ‘s/\(.*\)\..*/\1/’ | sort | uniq -c | grep -v “^[ \t]*1 ” > ~/find-duplicate.txt
- This will find duplicate filenames in the folder and its sub-folders
- sort myfile.txt | uniq
- This sort the lines in the file, also display unique lines only
- awk ‘NR==FNR{a[$0]=1;next}!a[$0]’ B.txt A.txt
- Find each lines, what’s in A.txt but not in B.txt file
Python Scripts
- mystring.zfill(8)
- fill the string to 8 character long with leading zeros. This is useful when listing IDs.
- mystring[-4:] ==> get last for character of mystring
- mystring[4:] ==> get the whole mystring minus the first 4 characters
- mystring.lstrip() ==> strip left (beginning) spaces
- mystring.rstrip() ==> strip right (end) spaces
PHP Scripts
vi
- :%s/[\x91\x92]/’/g
- This remove x91 and x92 characters