【leetcode-shell】Tenth Line
2017-06-21 15:01
197 查看
随便找了一个shell脚本的题目。
打印出第十行的内容。
解法一:循环,不过效率最差,排在了最后# Read from the file file.txt and output the tenth line to stdout.
#!/bin/bash
declare count=0
cat file.txt | while read line
do
if [ $count = 9 ];then
echo $line
exit 0
fi
let count=$count+1
done
解法二:sed,最快速,也最简洁
# Read from the file file.txt and output the tenth line to stdout.
#!/bin/bash
sed -n 10p file.txt
打印出第十行的内容。
解法一:循环,不过效率最差,排在了最后# Read from the file file.txt and output the tenth line to stdout.
#!/bin/bash
declare count=0
cat file.txt | while read line
do
if [ $count = 9 ];then
echo $line
exit 0
fi
let count=$count+1
done
解法二:sed,最快速,也最简洁
# Read from the file file.txt and output the tenth line to stdout.
#!/bin/bash
sed -n 10p file.txt
相关文章推荐
- [LeetCode][Shell]Tenth Line
- 【Leetcode Shell】Tenth Line
- 【leetcode~Shell】:Tenth Line
- leetcode-shell-192. Word Frequency
- leetcode 的shell部分4道题整理
- leetcode-shell-194. Transpose File
- 【Leetcode Shell】Valid Phone Numbers
- LeetCode:solution of shell problems
- LeetCode:Shell题目
- Leetcode: Word Frequency (shell , awk)
- leetcode-shell-195. Tenth Line
- leetcode-195 Tenth Line
- leetcode 新题型----SQL,shell,system design
- [LeetCode] Tenth Line 第十行
- LeetCode Shell
- LeetCode 195. Tenth Line (shell)
- [Leetcode Shell]Word Frequency
- Tenth Line(leetcode195-t4.sh)
- leetcode 新题型----SQL,shell,system design
- LeetCode 195 Tenth Line