随笔分类 - shell/python
摘要:例如:往文件file.txt中,添加一列字符串"20161020", 用制表符分割
阅读全文
摘要:读取文件的第2列和第4列: 求文件file1.txt的第二列 和 file2.txt(单列文件)的交集:
阅读全文
摘要:按照文件大小升序输出结果: 如果要逆序输出,则:
阅读全文
摘要:下面 hello 是开始时间, world 是结束时间
阅读全文
摘要:import os,shutil def copy_search_file(srcDir, desDir): ls = os.listdir(srcDir) for line in ls: filePath = os.path.join(srcDir, line) if os.path.isfile(filePath): ...
阅读全文
摘要:#!/usr/bin/env python #encoding: utf-8 import datetime def dateDiffInHours(t1, t2): td = t2 - t1 return td.days * 24 + td.seconds/3600 + 1 if __name__ == '__main__': t1 ...
阅读全文
摘要:如果 想利用 shell 从 json 数据 中 解析出某个字段, 可以 利用 正则匹配, 比如 想 解析出 "spanId":"8461203268866670975" 这个字段,可以利用如下 shell 脚本: 比如文件test1.txt中的其中一条数据: {"uid":"300","timeS
阅读全文
摘要:在一个局域网内,已知其中一台主机的ip为192.168.1.1,子网掩码为255.255.255.0,求所有其他在线主机的ip。shell 编码实现#!/bin/bashnetWorkIP=192.168.1.for host in $(seq 2 254)do ping -c 1 $netW...
阅读全文
摘要:words.txt中的内容如下:the day is sunny the the the sunny is is统计每个单词出现的次数,并降序输出。Unix Pipes脚本如下:cat words.txt | tr -s ' ' '\n' | sort | uniq -c | s...
阅读全文
摘要:在host1上,把下面的两行内容通过ssh追加到host2上的/etc/ca-certificates.conf文件中I am a studentAre you okssh host2 "echo -e \"I am a student\nAre you ok\" >> /etc/ca-certif...
阅读全文
摘要:declare -A animals=(["moo"]="cow" ["woof"]="dog")for sound in "${!animals[@]}";doecho "$sound - ${animals["$sound"]}";done
阅读全文
摘要:一、在当前目录及其子目录查找以mesos开头,并以.jar结尾的文件,并打印出来sudo find ./ -name mesos*.jar -print二、whereis, locate 也有类似功能。
阅读全文
摘要:问题描述: ubuntu下仅仅获取网卡一的ip地址问题背景: eth0,eth1,eth2……代表网卡一,网卡二,网卡三…… lo代表127.0.0.1,即localhostsudo ifconfig eth0 | grep 'inet addr' | cut -d : -f 2 | cut ...
阅读全文
摘要:问题描述: 把字符串tarFile和数组slaves_hostIP传入函数processArray中并输出结果.#!/bin/bashfunction processArray() { tarFile=$1 echo $tarFile local slaves_hostIP=($...
阅读全文
摘要:文件/etc/hdocker_config内容如下:30.72.63.94 30.72.63.95 30.72.63.96 30.72.63.97/tmp/lasclocker.tarmaster slave1 slave2 slave3实现功能:依次读取该文件的每一行,并赋值于数组tmp,并把数组...
阅读全文
浙公网安备 33010602011771号