Thursday, April 9, 2015

How to limit search to subfolders in shell

If you have a script where you search for a specific subgroup of files, you may pick up files that are in subfolders which you did not intend to modify. To prevent this use -maxdepth 1 parameter with find function

E.g. this script will find all files that contain gwasbed in their name, cut first 3 columns, sort and uniq, and save them with _uniq extension, then intersect _uniq files using bedtools, but it will not pick files from subfolders.

for f in $(find . -maxdepth 1 -name \*gwasbed\*)
echo "$f"
cut -f1,2,3 "$f" | sort -k1,2 | uniq> "$f"_uniq

for f in $(find . -maxdepth 1 -name \*_uniq\*)
bedtools intersect -a "$f" -b L2_TCCTGAGC_L002_peaks.bed > ./INTERSECT_output/"$f"_ATAC;

No comments:

Post a Comment