leetcode-shell-195. Tenth Line
来源:互联网 发布:软件著作是什么意思 编辑:程序博客网 时间:2024/06/05 19:17
How would you print just the 10th line of a file?
For example, assume that file.txt
has the following content:
Line 1Line 2Line 3Line 4Line 5Line 6Line 7Line 8Line 9Line 10Your script should output the tenth line, which is:
Line 10
题意:输出txt文件的第10行
思路:声明一个变量,记录行数,当行数=10的时候,输出当前行
最终shell脚本:
#! /bin/sh
filename=file.txt
i=1
cat $filename |while read line
do
if [ $i = 10 ] ;then
echo $line
fi
filename=file.txt
i=1
cat $filename |while read line
do
if [ $i = 10 ] ;then
echo $line
fi
i=$(($i+1))
done
需要值得注意的是:写if判断语句的时候,注意空格。[空格$i空格=空格10空格]空格;
在shell脚本中变量自增不能使用i++这种方式,要$i取出值+1再变成值(前加$号)赋值给变量,$(($i+1))
0 0
- leetcode-shell-195. Tenth Line
- LeetCode 195. Tenth Line (shell)
- 【Leetcode Shell】Tenth Line
- 【leetcode~Shell】:Tenth Line
- 【leetcode~Shell】:Tenth Line
- leetcode:Tenth Line 【shell】
- 【leetcode-shell】Tenth Line
- Leetcode 195. Tenth Line
- [Leetcode] 195. Tenth Line
- 195. Tenth Line leetcode bash
- leetcode-195 Tenth Line
- LeetCode 195 Tenth Line
- Leetcode: Tenth Line
- 195. Tenth Line
- 195. Tenth Line
- 195. Tenth Line#1
- 195. Tenth Line
- 195. Tenth Line。
- Tomcat配置https及访问http自动跳转至https
- leetcode-database-177. Nth Highest Salary
- 事件
- 自包含
- 缺少编译器要求的成员“System.Runtime.CompilerServices.ExtensionAttribute..ctor” 解决方案
- leetcode-shell-195. Tenth Line
- iOS 单元测试3- Singleton如何测试
- Android开发中无处不在的设计模式——Builder模式
- easyui combobox默认选中第一个
- 文件上传和下载功能
- javascript之闭包
- <marquee></marquee> 动画效果
- css的伪类和伪元素使用示例
- Fragment与FragmentActivity的关系