195. Tenth Line

#!/bin/bash
i=
cat file.txt | while read line
do
#echo $line
if [ $i -eq ]
then echo $line
fi let i=i+
done

194. Transpose File

# Read from the file file.txt and print its transposed content to stdout.
#########################################################################
# File Name: .sh
# Author: atrp
# mail: scau_zjl@.com
# Created Time: Thu May :: AM EDT
#########################################################################
#!/bin/bash
i=
function getLen() {
num_column=$#
}
read line < file.txt
getLen $line
while [ -lt ]
do
column=`cut -d' ' -f$i ./file.txt`
echo ${column}
if [ $i -eq ${num_column} ]
then
break
fi
let i++
done

193. Valid Phone Numbers

#########################################################################
# File Name: .sh
# Author: atrp
# mail: scau_zjl@.com
# Created Time: Wed May :: PM EDT
#########################################################################
#!/bin/bash
grep -P "^\(\d{3}\)\s\d{3}-\d{4}$|^\d{3}-\d{3}-\d{4}$" file.txt

192. Word Frequency

###########################################################################
# File Name: .sh
# Author: atrp
# mail: scau_zjl@.com
# Created Time: Thu May :: AM EDT
#########################################################################
#!/bin/bash
declare -A map1=()
function calc() {
#echo $@
for i in $@
do
let map1["$i"]++
#echo ${map1["$i"]}
done
}
function out() {
times=
while [ $times -lt ${#map1[@]} ]
do
max=
id=
for i in ${!map1[@]}
do
if [ ${max} -lt ${map1[$i]} ]
then
max=${map1[$i]}
id=$i
fi
done
echo "${id} ${max}"
map1[${id}]= let times++
done
}
while read line
do
#echo $line
calc $line
done < words.txt out

LeetCode Bash练习的更多相关文章

  1. bash 刷题leetcode

    题目一: 给定一个文本文件 file.txt,请只打印这个文件中的第十行. 示例: 假设 file.txt 有如下内容: Line 1 Line 2 Line 3 Line 4 Line 5 Line ...

  2. [LeetCode] 193. Valid Phone Numbers_Easy tag: Bash

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  3. 【leetcode】bash脚本练习

    [192]Word Frequency Write a bash script to calculate the frequency of each word in a text file words ...

  4. bash leetcode

    拓展:grep 193.  ref: https://blog.csdn.net/yanglingwell/article/details/82343407 Given a text file fil ...

  5. [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 ...

  6. [LeetCode] Tenth Line 第十行

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

  7. [LeetCode] Transpose File 转置文件

    Given a text file file.txt, transpose its content. You may assume that each row has the same number ...

  8. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  9. [LeetCode] Word Frequency 单词频率

    Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...

随机推荐

  1. jquery 往上滚动的时显示,上下滚动执行的js

    $(document).on("mousewheel DOMMouseScroll", function (e) { var delta = (e.originalEvent.wh ...

  2. task一个任务结束后执行另一个操作

    //创建一个任务 Task<int> task = new Task<int>(() => { ; //显示进度条遮照层, this.ShowPrograssBar(); ...

  3. 探究JavaScript闭包

    什么是JavaScript闭包? 刚开始知道这个词,就误以为是自动执行的匿名函数块. 比如说+function(){}(); 然而并不是,那么请看下面的例子: function init() { va ...

  4. C#关于private protected sealed Virtual/Override

    Public:公开权限 Private:修饰类时类为程序集或者包含此类的类内部权限:修饰变量时只能类内部使用: Protected:修饰变量,只能继承类可以使用,对外(包括继承类的实例)无权限: Ab ...

  5. requests+lxml+xpath爬取豆瓣电影

    (1)lxml解析html from lxml import etree #创建一个html对象 html=stree.HTML(text) result=etree.tostring(html,en ...

  6. Java中的substring()用法

    String str = "Hello Java World!"; Method1:  substring(int beginIndex) 返回从起始位置(beginIndex)至 ...

  7. 深入理解.NET Core的基元(二) - 共享框架

    原文:Deep-dive into .NET Core primitives, part 2: the shared framework 作者:Nate McMaster 译文:深入理解.NET Co ...

  8. MySQL:数据库基本认识

    1.什么是数据库 通俗来讲,数据库就是用于存储数据的仓库.很多人可能会问,存储数据用文件不就行了吗?为什么还要弄数据库? 文件存储数据具有以下几个缺点: 文件的安全性问题 文件不利于查询和数据库管理 ...

  9. 在windows主机中,利用XSHELL生成“密钥”进行虚拟机与物理机的传输

    首先你要有虚拟机,其次你要可以互相ping通(主机与虚拟机) 接着你要有xshell 软件  没有的话可以点击链接下载 Xshell  6  提取码:cj5t 打开Xshell软件  在工具栏中选择“ ...

  10. Mysql常用数据类型归纳总结1

    一直在用Mysql数据库,Mysql的数据类型也最常打交道的.但关于Mysql的一些常用数据类型了解程度仅限于一知半解,仅仅能满足满足于平时一些最简单的操作.而Mysql常用数据类型的定义以及规范理解 ...