File tree 9 files changed +94
-37
lines changed
9 files changed +94
-37
lines changed Original file line number Diff line number Diff line change 42
42
<!-- 这里可写当前语言的特殊实现逻辑 -->
43
43
44
44
``` sh
45
+ # Read from the file file.txt and output all valid phone numbers to stdout.
46
+ grep -P ' ^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$' file.txt
47
+ ```
45
48
49
+ ``` sh
50
+ # Read from the file file.txt and output all valid phone numbers to stdout.
51
+ sed -n -E ' /^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt
52
+ ```
53
+
54
+ ``` sh
55
+ # Read from the file file.txt and output all valid phone numbers to stdout.
56
+ awk ' /^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt
46
57
```
47
58
48
59
<!-- tabs:end -->
Original file line number Diff line number Diff line change 34
34
### ** Bash**
35
35
36
36
``` sh
37
+ # Read from the file file.txt and output all valid phone numbers to stdout.
38
+ grep -P ' ^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$' file.txt
39
+ ```
37
40
41
+ ``` sh
42
+ # Read from the file file.txt and output all valid phone numbers to stdout.
43
+ sed -n -E ' /^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt
44
+ ```
45
+
46
+ ``` sh
47
+ # Read from the file file.txt and output all valid phone numbers to stdout.
48
+ awk ' /^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt
38
49
```
39
50
40
51
<!-- tabs:end -->
Original file line number Diff line number Diff line change 1
- #! /usr/bin/env bash
2
-
3
- # -P : --perl-regexp
4
- grep -P ' ^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$' file.txt
5
-
6
- # or use sed
7
- sed -n -E ' /^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt
8
-
9
- # or use awk
1
+ # Read from the file file.txt and output all valid phone numbers to stdout.
10
2
awk ' /^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt
Original file line number Diff line number Diff line change @@ -40,7 +40,22 @@ age 21 30
40
40
<!-- 这里可写当前语言的特殊实现逻辑 -->
41
41
42
42
``` sh
43
-
43
+ # Read from the file file.txt and print its transposed content to stdout.
44
+ awk '
45
+ {
46
+ for (i=1; i<=NF; i++) {
47
+ if(NR == 1) {
48
+ res[i] = re$i
49
+ } else {
50
+ res[i] = res[i]" "$i
51
+ }
52
+ }
53
+ }END {
54
+ for (i=1;i<=NF;i++) {
55
+ print res[i]
56
+ }
57
+ }
58
+ ' file.txt
44
59
```
45
60
46
61
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -32,7 +32,22 @@ age 21 30
32
32
### ** Bash**
33
33
34
34
``` sh
35
-
35
+ # Read from the file file.txt and print its transposed content to stdout.
36
+ awk '
37
+ {
38
+ for (i=1; i<=NF; i++) {
39
+ if(NR == 1) {
40
+ res[i] = re$i
41
+ } else {
42
+ res[i] = res[i]" "$i
43
+ }
44
+ }
45
+ }END {
46
+ for (i=1;i<=NF;i++) {
47
+ print res[i]
48
+ }
49
+ }
50
+ ' file.txt
36
51
```
37
52
38
53
<!-- tabs:end -->
Original file line number Diff line number Diff line change 1
- #! /usr/bin/env bash
2
-
3
- awk '
4
- {
5
- for (i=1; i<=NF; i++) {
6
- if(NR == 1) {
7
- res[i] = re$i
8
- } else {
9
- res[i] = res[i]" "$i
10
- }
11
- }
12
- }END {
13
- for (i=1;i<=NF;i++) {
14
- print res[i]
15
- }
16
- }
1
+ # Read from the file file.txt and print its transposed content to stdout.
2
+ awk '
3
+ {
4
+ for (i=1; i<=NF; i++) {
5
+ if(NR == 1) {
6
+ res[i] = re$i
7
+ } else {
8
+ res[i] = res[i]" "$i
9
+ }
10
+ }
11
+ }END {
12
+ for (i=1;i<=NF;i++) {
13
+ print res[i]
14
+ }
15
+ }
17
16
' file.txt
Original file line number Diff line number Diff line change @@ -44,7 +44,18 @@ Line 10
44
44
<!-- 这里可写当前语言的特殊实现逻辑 -->
45
45
46
46
``` sh
47
+ # Read from the file file.txt and output the tenth line to stdout.
48
+ tail -n +10 file.txt | head -1
49
+ ```
47
50
51
+ ``` sh
52
+ # Read from the file file.txt and output the tenth line to stdout.
53
+ awk ' NR == 10' file.txt
54
+ ```
55
+
56
+ ``` sh
57
+ # Read from the file file.txt and output the tenth line to stdout.
58
+ sed -n 10p file.txt
48
59
```
49
60
50
61
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -40,7 +40,18 @@ Line 10
40
40
### ** Bash**
41
41
42
42
``` sh
43
+ # Read from the file file.txt and output the tenth line to stdout.
44
+ tail -n +10 file.txt | head -1
45
+ ```
43
46
47
+ ``` sh
48
+ # Read from the file file.txt and output the tenth line to stdout.
49
+ awk ' NR == 10' file.txt
50
+ ```
51
+
52
+ ``` sh
53
+ # Read from the file file.txt and output the tenth line to stdout.
54
+ sed -n 10p file.txt
44
55
```
45
56
46
57
<!-- tabs:end -->
Original file line number Diff line number Diff line change 1
- #! /usr/bin/env bash
2
-
3
- # tail -n: use -n +K to output starting with the Kth
4
- tail -n +10 file.txt | head -1
5
-
6
- # awk:
7
- awk ' NR == 10' file.txt
8
-
9
- # sed:
10
- sed -n 10p file.txt
1
+ # Read from the file file.txt and output the tenth line to stdout.
2
+ sed -n 10p file.txt
You can’t perform that action at this time.
0 commit comments