Leetcode 195 Tenth Line
Given a text file file.txt, print just the 10th line of the file.
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
1. If the file contains less than 10 lines, what should you output?
2. There's at least three different solutions. Try to explore all possibilities.
awk 'NR == 10' file.txt
/*
awk [-F field-separator] 'commands' input-file(s)
*/
Detail describe of awk in bash,please click in:
https://www.cyberciti.biz/faq/bash-scripting-using-awk/ Comment: this is my first blog article,if there are something wrong in the article,please point out,thanks.
Leetcode 195 Tenth Line的更多相关文章
- [LeetCode] 195. Tenth Line 第十行
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- 195 Tenth Line
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- [LeetCode] 195. Tenth Line_Easy tag: Bash
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- [LeetCode] Tenth Line 第十行
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- LeetCode OJ:Tenth Line(文件第十行)
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- 刷题中熟悉Shell命令之Tenth Line和Transpose File [leetcode]
首先介绍题目中要用的4个Shell命令 sed awk head tail的常用方法.(打好地基,才能建成高楼!) sed:(转自:http://www.cnblogs.com/barrychiao/ ...
- [Bash]LeetCode195. 第十行 | Tenth Line
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- Tenth Line
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- LeetCode 562. Longest Line of Consecutive One in Matrix(在矩阵中最长的连续1)$
Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horiz ...
随机推荐
- python chrome selenium
#coding=utf-8 from selenium import webdriver options = webdriver.ChromeOptions() options.add_argumen ...
- IT回忆录-2
随着网络的发展,下载工具也不断地更新. 印象比较深的下载工具,从网络蚂蚁.网际快车,到BT. BT出来的时候,对下载真的是一个革命啊,以前下载东西,下载的人越多肯定就越慢,我们之前还会跑到一些FTP上 ...
- Advanced Installer 安装前卸载旧版本的办法
原文:Advanced Installer 安装前卸载旧版本的办法 Advanced Installer这个工具百度出来的资料太少了. 在我们平常打包的工作中,经常遇到的一个问题是,如何能在安装新版本 ...
- Android零基础入门第55节:ImageSwitcher和TextSwitcher使用
原文:Android零基础入门第55节:ImageSwitcher和TextSwitcher使用 上一期我们了解了ViewAnimator组件和ViewSwitcher组件的使用,你都掌握了吗?本期一 ...
- 02ython基础知识(一)
Python基础知识(一) 变量 name='monkeyfx' 变量定义的规则: 变量名只能是 字母.数字或下划线的任意组合 变量名的第一个字符不能是数字 以下关键字不能声明为变量名: ['and' ...
- Linux之mysql安装
查看文件内容的命令有很多:cat, tac, more, less, head, tail, nl. cat由第一行开始显示档案内容:tac从最后一行开始显示,可以看出tac是cat的倒着写:more ...
- 该内存不能read 或written数值 叙述(居然还有具体的讲究)
该内存不能read 或written数值 叙述 0 0x0000 作业完成. 1 0x0001 不正确的函数. 2 0x0002 系统找不到指定的档案. 3 0x0003 系统找不到指定的路径. 4 ...
- QT Udp组播(穿透)
http://blog.csdn.net/victoryknight/article/details/7814243 主题 UDPQt路由器 局域网内的两台机器如果隔有路由器,那么这两台机器之间不 ...
- SqlServer 动态SQL(存储过程)中Like 传入参数无正确返回值的问题
最近在做项目时,以动态Sql进行Like语句查询时发现应该返回的结果却一直返回空,后来发现是写法错误: 错误SQL: DECLARE @0 varchar(20) SET @0 = 'XA-LZ' S ...
- uc手机浏览器使用animation的一个坑
最近做一个项目,应用在移动端,其中涉及一个评论组件.按照现有的趋势,是有评论的地方必有点赞.当然我们的组件也未免于难.大概操作部分设计如下 如此简low的设计,点个赞加个一这效果实在是简直是捞比啊!! ...