Created
August 24, 2015 01:31
-
-
Save byteface/54dfd290165d2cefe296 to your computer and use it in GitHub Desktop.
some bash stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# LOGGING ------------------ | |
# log to output file | |
log(){ | |
message=$( echo `date +%T` - $1 ) | |
echo $message >> 'json/'$LOGFILE | |
} | |
# create a log file | |
LOGFILE=$( echo `date +%F_%T`.log ) | |
#touch 'json/'$LOGFILE | |
log 'LOG FILE CREATED - READY TO IMPORT DATA' | |
log '***************************************' | |
log '' | |
# utils ------------------ | |
# json array from comma string | |
json_array() { | |
echo -n '[' | |
while [ $# -gt 0 ]; do | |
x=${1//\\/\\\\} | |
echo -n \"${x//\"/\\\"}\" | |
[ $# -gt 1 ] && echo -n ',' | |
shift | |
done | |
echo ']' | |
} | |
export -f json_array | |
#bash array from string | |
ar_string=$( echo $string | sed 's/ //g' ) | |
# printf '%s\n' "${ar_string[@]}" | |
# echo ${#ar_string[@]} | |
# turn array string into a bash array | |
IFS=',' read -a my_array <<< "ar_string" | |
for each in "${my_array[@]}" | |
do | |
#slice - change number for different slash | |
local car="$(echo "$path" | cut -d '/' -f 3)" | |
echo "car:"$car |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment