-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwc.sh
More file actions
84 lines (42 loc) · 1.22 KB
/
wc.sh
File metadata and controls
84 lines (42 loc) · 1.22 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
## Line, word and byte counts
cat greeting.txt
wc greeting.txt
## Individual counts
wc -l greeting.txt
wc -w greeting.txt
wc -c greeting.txt
wc -wc greeting.txt
printf 'hello' | wc -c
printf 'hello' | wc -c -
lines=$(wc -l <greeting.txt)
echo "$lines"
## Multiple files
wc greeting.txt nums.txt purchases.txt
wc greeting.txt nums.txt purchases.txt | tail -n1
wc *[ck]*.csv
printf 'greeting.txt\0nums.txt' | wc --files0-from=-
## Character count
printf 'αλεπού' | wc -c
printf 'αλεπού' | wc -m
printf 'αλεπού' | LC_ALL=C wc -m
## Longest line length
echo 'apple' | wc -L
printf 'apple\nbanana' | wc -L
wc -L sample.txt
wc -L <sample.txt
wc -L greeting.txt nums.txt purchases.txt
## Corner cases
printf 'good\nmorning\n' | wc -l
printf 'good\nmorning' | wc -l
printf '\n\n\n' | wc -l
echo 'apple ; banana ; cherry' | wc -w
echo 'apple ; banana ; cherry' | tr -cd 'a-zA-Z[:space:]'
echo 'apple ; banana ; cherry' | tr -cd 'a-zA-Z[:space:]' | wc -w
echo '2 : apples ;' | tr -cd '[:alnum:][:space:]' | wc -w
printf '\t' | wc -L
printf 'a\tb' | wc -L
printf 'a\34b' | wc -L
printf 'αλεπού' | wc -L
printf 'αλεπού' | LC_ALL=C wc -L
printf 'cag̈e' | wc -m
printf 'cag̈e' | wc -L