Skip to content

Commit

Permalink
solve tenthLine
Browse files Browse the repository at this point in the history
  • Loading branch information
int32bit committed Apr 10, 2015
1 parent 3ca1570 commit 507cb8a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
+ [192 Word Frequency](shell/WordFrequency)
+ [193 Valid Phone Numbers](shell/ValidPhoneNumbers)
+ [194 Transpose File](shell/TransposeFile)
+ [195 Tenth Line](shell/TenthLine)
33 changes: 33 additions & 0 deletions shell/TenthLine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Tenth Line

## Problem

How would you print just the 10th line of a file?

For example, assume that `file.txt` has the following content:
```
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
```
Your script should output the tenth line, which is:
```
Line 10
```

## Solution

直接使用sed搞定

## Code
```bash
#!/bin/bash
sed -n '10p' file.txt
```
10 changes: 10 additions & 0 deletions shell/TenthLine/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
2 changes: 2 additions & 0 deletions shell/TenthLine/tenthLine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sed -n '10p' file.txt

0 comments on commit 507cb8a

Please sign in to comment.