-
Notifications
You must be signed in to change notification settings - Fork 0
/
head_tail.sh
82 lines (60 loc) · 1.98 KB
/
head_tail.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
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
#!/bin/bash/
filepath='sampleTexts/head_tail.txt'
n=10
echo "---- Display first n characters ----"
head -c $n $filepath
n=1100
echo -e "\n\n---- Display all characters except the last n characters ----"
head -c -$n $filepath
n=4
echo -e "\n\n---- Display first n lines ----"
head -n $n $filepath
n=20
echo -e "\n---- Display all lines except the last n lines ----"
head -n -$n $filepath
n=10
echo -e "\n\n---- Display last n characters ----"
tail -c $n $filepath
n=1100
echo -e "\n\n---- Display all characters from the nth character ----"
tail -c +$n $filepath
n=4
echo -e "\n\n---- Display last n lines ----"
tail -n $n $filepath
n=20
echo -e "\n\n---- Display all lines from the nth line ----"
tail -n +$n $filepath
: """
Output:
---- Display first n characters ----
From faire
---- Display all characters except the last n characters ----
From fairest creatures we
---- Display first n lines ----
From fairest creatures we desire increase,
That thereby beauty's rose might never die,
But as the riper should by time decease,
His tender heir might bear his memory:
---- Display all lines except the last n lines ----
From fairest creatures we desire increase,
That thereby beauty's rose might never die,
But as the riper should by time decease,
His tender heir might bear his memory:
But thou contracted to thine own bright eyes,
---- Display last n characters ----
ld excuse'
---- Display all characters from the nth character ----
nt, and make my old excuse'
---- Display last n lines ----
Were an all-eating shame, and thriftless praise.
How much more praise deserved thy beauty's use,
If thou couldst answer 'This fair child of mine
Shall sum my count, and make my old excuse'
---- Display all lines from the nth line ----
Where all the treasure of thy lusty days;
To say within thine own deep sunken eyes,
Were an all-eating shame, and thriftless praise.
How much more praise deserved thy beauty's use,
If thou couldst answer 'This fair child of mine
Shall sum my count, and make my old excuse'
"""