-
Notifications
You must be signed in to change notification settings - Fork 4
/
func_dim.sh
52 lines (49 loc) · 1.15 KB
/
func_dim.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
dim() {
# Count the number of rows in file(s) and columns in file(s) header
# $1 $2 = potentially a delimiter, i.e., -d ,
# (these two arguments are optional and -d must be the first)
# $@ = file names
local DELIM FILE NROW NCOL
if [[ $1 == "-d" ]]; then
DELIM=$2
shift 2
else
DELIM=" "
fi
# echo "DELIM is |$DELIM|"
# echo "args are $@"
for FILE in "$@"; do
NROW=$(wc -l "$FILE" | awk '{ print $1 }')
NCOL=$(head -n 1 "$FILE" | awk -F "$DELIM" '{ print NF }')
echo "$NROW $NCOL $FILE"
unset NROW NCOL
done
}
nrow() {
# Count the number of rows in file(s)
# $@ = file names
local FILE
for FILE in "$@"; do
wc -l "$FILE"
done
}
ncol() {
# Count the number of columns in file(s) header
# $1 $2 = potentially a delimiter, i.e., -d ,
# (these two arguments are optional and -d must be the first)
# $@ file names
local DELIM FILE NCOL
if [[ $1 == "-d" ]]; then
DELIM=$2
shift 2
else
DELIM=" "
fi
# echo "DELIM is |$DELIM|"
# echo "args are $@"
for FILE in "$@"; do
NCOL=$(head -n 1 "$FILE" | awk -F "$DELIM" '{ print NF }')
echo "$NCOL $FILE"
unset NCOL
done
}