-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfunc_see.sh
More file actions
101 lines (89 loc) · 2.71 KB
/
Copy pathfunc_see.sh
File metadata and controls
101 lines (89 loc) · 2.71 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# see & see_col
#-------------------------------------------------------------------------------
see() {
# See file contents quickly, i.e., head and tail
# $@ = file names
local lines=5
local col_limit=20
for f in "$@"; do
local nc=$(head -n 1 "$f" | awk '{ print NF }')
if (( nc > col_limit )); then
echo -e "\nMore than ${col_limit} columns, using see_col!"
see_col "$f"
else
local nr=$(wc -l | awk '{ print $1 }')
echo "\n$f, nrow=$nr, ncol=$nc"
head -n $lines "$f"
if (( nr > lines )); then
echo "..."
echo "..."
echo "..."
tail -n $lines "$f"
fi
fi
done
}
see_col() {
# See file contents quickly, i.e., head and tail (only a few columns)
# $@ = file names
local lines=5
for f in "$@"; do
local nc=$(head -n 1 "$f" | awk '{ print NF }')
local nr=$(wc -l | awk '{ print $1 }')
echo "\n$f, nrow=$nr, ncol=$nc"
# TODO: see comments in head_col
local scr
if (( nc <= 10 )); then
scr='{ out=$1; for (i=2; i<=10; i++) { out=out" "$i }; print out }'
else
scr='{ out=$1; for (i=2; i<=10; i++) { out=out" "$i }; print out" ... "$nc }'
fi
head -n $lines "$f" | awk "$scr"
if (( nr > lines )); then
echo "..."
echo "..."
echo "..."
tail -n $lines "$f" | awk "$scr"
fi
done
}
# head_col & tail_col
#-------------------------------------------------------------------------------
head_col() {
# Show first rows and cols of a file, i.e., just first few
# rows and first few columns (useful when a file is very big)
# $@ = file names
# TODO: can we make no of cols an option?
# TODO: delimiter as an option
# TODO: combine {head,tail,see}_col as most code is the same
for f in "$@"; do
local nc=$(head -n 1 "$f" | awk '{ print NF }')
local nr=$(wc -l | awk '{ print $1 }')
echo "\n$f, nrow=$nr, ncol=$nc"
local scr
if (( nc <= 10 )); then
scr='{ out=$1; for (i=2; i<=10; i++) { out=out" "$i }; print out }'
else
scr='{ out=$1; for (i=2; i<=10; i++) { out=out" "$i }; print out" ... "$nc }'
fi
head "$f" | awk "$scr"
done
}
tail_col() {
# Show last rows and cols of a file, i.e., just last few
# rows and last few columns (useful when a file is very big)
# $@ = file names
for f in "$@"; do
local nc=$(head -n 1 "$f" | awk '{ print NF }')
local nr=$(wc -l | awk '{ print $1 }')
echo "\n$f, nrow=$nr, ncol=$nc"
## TODO: see above comments in head_col
local scr
if (( nc <= 10 )); then
scr='{ out=$1; for (i=2; i<=10; i++) { out=out" "$i }; print out }'
else
scr='{ out=$1; for (i=2; i<=10; i++) { out=out" "$i }; print out" ... "$nc }'
fi
tail "$f" | awk "$scr"
done
}