Skip to content

Instantly share code, notes, and snippets.

@dgcamblor
Last active July 3, 2024 11:06
Show Gist options
  • Save dgcamblor/941eff4040c06e5c9f89f786451f05e9 to your computer and use it in GitHub Desktop.
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)
#!/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