Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions solution/0100-0199/0193.Valid Phone Numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@
<!-- 这里可写当前语言的特殊实现逻辑 -->

```sh
# Read from the file file.txt and output all valid phone numbers to stdout.
grep -P '^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$' file.txt
```

```sh
# Read from the file file.txt and output all valid phone numbers to stdout.
sed -n -E '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt
```

```sh
# Read from the file file.txt and output all valid phone numbers to stdout.
awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt
```

<!-- tabs:end -->
11 changes: 11 additions & 0 deletions solution/0100-0199/0193.Valid Phone Numbers/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@
### **Bash**

```sh
# Read from the file file.txt and output all valid phone numbers to stdout.
grep -P '^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$' file.txt
```

```sh
# Read from the file file.txt and output all valid phone numbers to stdout.
sed -n -E '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt
```

```sh
# Read from the file file.txt and output all valid phone numbers to stdout.
awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt
```

<!-- tabs:end -->
10 changes: 1 addition & 9 deletions solution/0100-0199/0193.Valid Phone Numbers/Solution.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
#!/usr/bin/env bash

# -P : --perl-regexp
grep -P '^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$' file.txt

# or use sed
sed -n -E '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt

# or use awk
# Read from the file file.txt and output all valid phone numbers to stdout.
awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt
17 changes: 16 additions & 1 deletion solution/0100-0199/0194.Transpose File/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,22 @@ age 21 30
<!-- 这里可写当前语言的特殊实现逻辑 -->

```sh

# Read from the file file.txt and print its transposed content to stdout.
awk '
{
for (i=1; i<=NF; i++) {
if(NR == 1) {
res[i] = re$i
} else {
res[i] = res[i]" "$i
}
}
}END {
for (i=1;i<=NF;i++) {
print res[i]
}
}
' file.txt
```

<!-- tabs:end -->
17 changes: 16 additions & 1 deletion solution/0100-0199/0194.Transpose File/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,22 @@ age 21 30
### **Bash**

```sh

# Read from the file file.txt and print its transposed content to stdout.
awk '
{
for (i=1; i<=NF; i++) {
if(NR == 1) {
res[i] = re$i
} else {
res[i] = res[i]" "$i
}
}
}END {
for (i=1;i<=NF;i++) {
print res[i]
}
}
' file.txt
```

<!-- tabs:end -->
31 changes: 15 additions & 16 deletions solution/0100-0199/0194.Transpose File/Solution.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/usr/bin/env bash

awk '
{
for (i=1; i<=NF; i++) {
if(NR == 1) {
res[i] = re$i
} else {
res[i] = res[i]" "$i
}
}
}END {
for (i=1;i<=NF;i++) {
print res[i]
}
}
# Read from the file file.txt and print its transposed content to stdout.
awk '
{
for (i=1; i<=NF; i++) {
if(NR == 1) {
res[i] = re$i
} else {
res[i] = res[i]" "$i
}
}
}END {
for (i=1;i<=NF;i++) {
print res[i]
}
}
' file.txt
11 changes: 11 additions & 0 deletions solution/0100-0199/0195.Tenth Line/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,18 @@ Line 10
<!-- 这里可写当前语言的特殊实现逻辑 -->

```sh
# Read from the file file.txt and output the tenth line to stdout.
tail -n +10 file.txt | head -1
```

```sh
# Read from the file file.txt and output the tenth line to stdout.
awk 'NR == 10' file.txt
```

```sh
# Read from the file file.txt and output the tenth line to stdout.
sed -n 10p file.txt
```

<!-- tabs:end -->
11 changes: 11 additions & 0 deletions solution/0100-0199/0195.Tenth Line/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ Line 10
### **Bash**

```sh
# Read from the file file.txt and output the tenth line to stdout.
tail -n +10 file.txt | head -1
```

```sh
# Read from the file file.txt and output the tenth line to stdout.
awk 'NR == 10' file.txt
```

```sh
# Read from the file file.txt and output the tenth line to stdout.
sed -n 10p file.txt
```

<!-- tabs:end -->
12 changes: 2 additions & 10 deletions solution/0100-0199/0195.Tenth Line/Solution.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
#!/usr/bin/env bash

# tail -n: use -n +K to output starting with the Kth
tail -n +10 file.txt | head -1

# awk:
awk 'NR == 10' file.txt

# sed:
sed -n 10p file.txt
# Read from the file file.txt and output the tenth line to stdout.
sed -n 10p file.txt