Last active
March 26, 2016 08:13
-
-
Save chintak/8c53634e283654f30f94 to your computer and use it in GitHub Desktop.
Shell tricks
This file contains 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
# Process files in a loop with arbitrary names | |
while IFS= read -r -d '' f; do | |
cp "$f" /path2/ | |
done < <(find /path/ -wholename '*.mp3' -print0) | |
# Find a pattern and replace in place using sed | |
ls /path/*.csv -1 | grep "subj[0-9]_" | sed -n "s/\(.*subj\)\([0-9].*\)/mv \1\2 \10\2/p" | |
# Count the number of files in each sub directory and write to a file | |
find images/ -maxdepth 1 -print0 | xargs -0 -n 1 -I dir sh -c 'printf dir"\t"; find dir/ -name "*.jpg" | wc -l' &> distribution.txt | |
# Count the number of files in each sub directory, check against a threshold and write to a file | |
find images/ -maxdepth 1 -print0 | xargs -0 -n 1 -I dir sh -c 'printf dir"\t"; find dir/ -name "*.jpg" | wc -l' | \ | |
awk '{ split($0,a,"/"); split(a[2],b,"\t"); printf ($NF < 500) ? (b[1] != "") ? b[1]"\t"b[2]"\n" : "" : "" }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment