-
Notifications
You must be signed in to change notification settings - Fork 0
/
cut.sh
33 lines (29 loc) · 992 Bytes
/
cut.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
sample="Hello how are you"
i=2
j=5
echo "---- Command cut with Option -c for characters ----"
echo $sample | cut -c$i # return ith character
echo $sample | cut -c$i-$j # return characters from i-j
echo $sample | cut -c$i- # return characters from i to end
echo $sample | cut -c-$j # return characters from start to j
# default --delimiter is '\t' but we need whitespace ' ' in our case
i=2
j=3
echo "---- Command cut with Option -f for fields ----"
echo $sample | cut -d$' ' -f$i # return ith field(word)
echo $sample | cut -d$' ' -f$i-$j # return fields from i to j
echo $sample | cut -d$' ' -f$i- # return fields from i to end
echo $sample | cut -d$' ' -f-$j # return fields from start to j
: '
Output:
---- Command cut with Option -c for characters ----
e
ello
ello how are you
Hello
---- Command cut with Option -f for fields ----
how
how are
how are you
Hello how are
'