Last active
July 3, 2024 11:06
-
-
Save dgcamblor/941eff4040c06e5c9f89f786451f05e9 to your computer and use it in GitHub Desktop.
List all samples in a raw data directory (single line, multiple line list or count them)
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
#!/bin/bash | |
list_samples() { | |
local dir="$1" | |
local mode="${2:-line}" | |
local samples=$(ls -1 "$dir" | awk -F'_' '{print $1}' | sort -uV) | |
case "$mode" in | |
line) | |
echo "$samples" | paste -sd ' ' - | |
;; | |
list) | |
echo "$samples" | |
;; | |
count) | |
echo "$samples" | wc -l | |
;; | |
*) | |
echo "Invalid mode. Use 'line', 'list', or 'count'." | |
exit 1 | |
;; | |
esac | |
} | |
export -f list_samples | |
# Example usage: | |
# ./script.sh /path/to/directory line | |
# ./script.sh /path/to/directory list | |
# ./script.sh /path/to/directory count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment