Handy bash scripts
Installation
-
Save the scripts somewhere in your directory. For instance
~/code/shell_scripts/
-
Add to your
~/.zshrc
or~/.bashrc
(depending on your shell)
alias header="SOME_DIR/header.sh"
alias search="SOME_DIR/search.sh"
Use
header.sh
header transposes the header the header row of a csv file.
The script takes three arguments:
- path to a csv file (str)
- field separator (str, optional, default=',')
- header's line number (int, optional, default='1')
Syntax
header A_CSV_FILE.csv [FIELD_SEP] [HEADER_LINE_NUMBER]
search.sh
search looks up for a string in files' content inside a directory and print all the lines containing the string.
The script takes two arguments:
- pattern to look for (str, can be regex expression)
- regex for filename (str, optional, default='*')
Syntax
search REGEX [REGEX_FILENAME]
Example
search 'hello*world' *.py