Check These Out
tree has lots of parms - man is your friend
Copies a dir structure without the files in it.
I like much more the perl solution, but without using perl. It launches a backgroup process that will kill the command if it lasts too much.
A bigger function:
check_with_timeout() {
[ "$DEBUG" ] && set -x
COMMAND=$1
TIMEOUT=$2
RET=0
# Launch command in backgroup
[ ! "$DEBUG" ] && exec 6>&2 # Link file descriptor #6 with stderr.
[ ! "$DEBUG" ] && exec 2> /dev/null # Send stderr to null (avoid the Terminated messages)
$COMMAND 2>&1 >/dev/null &
COMMAND_PID=$!
[ "$DEBUG" ] && echo "Background command pid $COMMAND_PID, parent pid $$"
# Timer that will kill the command if timesout
sleep $TIMEOUT && ps -p $COMMAND_PID -o pid,ppid |grep $$ | awk '{print $1}' | xargs kill &
KILLER_PID=$!
[ "$DEBUG" ] && echo "Killer command pid $KILLER_PID, parent pid $$"
wait $COMMAND_PID
RET=$?
# Kill the killer timer
[ "$DEBUG" ] && ps -e -o pid,ppid |grep $KILLER_PID | awk '{print $1}' | xargs echo "Killing processes: "
ps -e -o pid,ppid |grep -v PID | grep $KILLER_PID | awk '{print $1}' | xargs kill
wait
sleep 1
[ ! "$DEBUG" ] && exec 2>&6 6>&- # Restore stderr and close file descriptor #6.
return $RET
}
txt2regex can be interactive or noninteractive and generates regular expressions for a variety of dialects based on user input. In interactive mode, the regex string builds as you select menu options. The sample output here is from noninteractive mode, try running it standalone and see for yourself. It's written in bash and is available as the 'txt2regex' package at least under debian/ubuntu.
Starting with a large MySQL dump file (*.sql) remove any lines that have inserts for the specified table. Sometimes one or two tables are very large and uneeded, eg. log tables. To exclude multiple tables you can get fancy with sed, or just run the command again on subsequently generated files.
Rather than chain a string of greps together and pipe them to awk, use awk to do all the work. In the above example, a string would be output to stdout if it matched pattern1 AND pattern2, but NOT pattern3.
It requires https://jqplay.org/, that comes with brew: brew install jq