-
Notifications
You must be signed in to change notification settings - Fork 31
/
cut.txt
220 lines (161 loc) · 2.96 KB
/
cut.txt
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
__Lets Say we have a input file__
```console
root@root:~/Desktop/temp# cat file.txt
name:age:color
one:1:111
two:2:222
three:3:333
```
__Reading Bytes__
```console
root@root:~/Desktop/temp# cat file.txt | cut -b 1
n
o
t
t
root@root:~/Desktop/temp# cat file.txt | cut -b 1,2,3
nam
one
two
thr
```
__Reading Byte Range__
```console
root@root:~/Desktop/temp# cat file.txt | cut -b 1-3
nam
one
two
thr
root@root:~/Desktop/temp# cat file.txt | cut -b -4 [Starting to 4]
name
one:
two:
thre
root@root:~/Desktop/temp# cat file.txt | cut -b 2- [start from 2 to end]
ame:age:color
ne:1:111
wo:2:222
hree:3:333
```
__Reading 1 character__
```console
root@root:~/Desktop/temp# cat file.txt | cut -c 1
n
o
t
t
```
__Reading 1-3 characters__
```console
root@root:~/Desktop/temp# cat file.txt | cut -c 1-3
nam
one
two
thr
```
__Reading starting-3 characters__
```console
root@root:~/Desktop/temp# cat file.txt | cut -c -3
nam
one
two
thr
```
__Reading characters from 3 to end__
```console
root@root:~/Desktop/temp# cat file.txt | cut -c 3-
me:age:color
e:1:111
o:2:222
ree:3:333
```
__Using Delimiter to extract 1st field__
```console
root@root:~/Desktop/temp# cat file.txt | cut -d":" -f1
name
one
two
three
```
__Using Delimiter to extract 1st and 2nd field__
```
root@root:~/Desktop/temp# cat file.txt | cut -d":" -f1,2
name:age
one:1
two:2
three:3
```
__Using reverse Match (Not gate)__
```console
root@root:~/Desktop/temp# cat file.txt | cut -d":" -f1,2
name:age
one:1
two:2
three:3
root@root:~/Desktop/temp# cat file.txt | cut -d":" -f1,2 --complement
color
111
222
333
```
__Using Output Delimiters__
```console
root@root:~/Desktop/temp# cat file.txt | cut -d":" -f1,2 --output-delimiter=~
name~age
one~1
two~2
three~3
root@root:~/Desktop/temp# cat file.txt | cut -d":" -f1,2,3 --output-delimiter=~
name~age~color
one~1~111
two~2~222
three~3~333
```
__Example 1: Removing protocols from Urls__
```console
root@root:~/Desktop/temp# cat file.txt
https://google.com
https://facebook.com
https://imran.com
http://example.com
root@root:~/Desktop/temp# cat file.txt | cut -d"/" -f3
google.com
facebook.com
imran.com
example.com
```
__Example 2: Extracting Domains from URLS__
```console
root@root:~/Desktop/temp# cat file.txt
https://google.com?name=imran&age=xxx&age=xxx
https://facebook.com?name=imran&age=xxx&age=xxx&age=xxx
https://imran.com?name=imran&age=xxx&age=xxx&age=xxx
http://example.com?name=imran&age=xxx&age=xxx
root@root:~/Desktop/temp# cat file.txt | cut -d"?" -f1
https://google.com
https://facebook.com
https://imran.com
http://example.com
```
__Example 3 : Extracting Keys/Values from JSON Object__
```console
root@root:~/Desktop/temp# cat file.txt
{
"a":"1",
"b":"2",
"c":"3",
}
root@root:~/Desktop/temp# cat file.txt | grep ':'
"a":"1",
"b":"2",
"c":"3",
root@root:~/Desktop/temp# cat file.txt | grep ':' | cut -d':' -f1
"a"
"b"
"c"
root@root:~/Desktop/temp# cat file.txt | grep ':' | cut -d':' -f2
"1",
"2",
"3",
root@root:~/Desktop/temp#
```