python 2.7.5 获取文本关键字符所在行
2024-10-06 20:56:05
#!/usr/bin/env python
#-*- coding: UTF- -*-
from __future__ import print_function
import time,os,sys,re,subprocess,commands,itertools,readline dt=time.localtime()
ft=" %Y-%m-%d %H:%M:%S %p %A"
date=time.strftime(ft,dt)
print(" 当前系统时间为:\n",date) #---------------------------------------------------------------------------------
#f0 = open('/etc/ssh/sshd_config','r')
#f1 = f0.readline()
#def get_number():
#sshd_config = "/etc/ssh/sshd_config"
#with open(sshd_config,'r') as f:
#for line in f.readlines():
#try:
#if'Port' in line:
#strlist = line.split('Port ')
#for sshdport in strlist[:]:
#print(sshdport)
#except:
#print('获取失败')
#if __name__ == '__main__':
#get_number()
#---------------------------------------------------------------------------------
#f = open('/etc/ssh/sshd_config','r')
#lines = f.readlines()
#for line in lines:
#if "Port " in line:
#print(line) #[root@localhost ~]# python .py
#当前系统时间为:
#-- :: PM Thursday
#Port
#--------------------------------------------------------------------------------- #yum install -y python python-devel #
#Port
#AddressFamily any #with open('/etc/ssh/sshd_config') as infile, open('/root/1.txt', 'w') as outfile:
#copy = False
#for line in infile:
#if line.strip() == "#":
#copy = True
#elif line.strip() == "#AddressFamily any":
#copy = False
#elif copy:
#outfile.write(line)
#[root@localhost ~]# cat .txt
#Port #---------------------------------------------------------------------------------
#pathfile = raw_input('文件绝对路径:')
#keyname = raw_input('查找内容:') #FoundFlag = False
#f00 = open(pathfile)
#f01 = f00.readline()
#while f01:
#if f01.find(keyname) == 0:
#FoundFlag = True
#print("---------------------------------------------------------------------------------")
#print(" 所在行: " + f01, end='')
#print("---------------------------------------------------------------------------------")
#break
#else:
#f01 = f00.readline()
#f00.close()
#if FoundFlag == False:
#print("获取失败.....!")
#raw_input() # 从下标0开始,查找在字符串里第一个出现的子串,返回结果: #[root@localhost ~]# python .py
#文件绝对路径:/etc/ssh/sshd_config
#查找内容:#Port
#---------------------------------------------------------------------------------
#所在行: #Port
#--------------------------------------------------------------------------------- #[root@localhost ~]# python .py
#文件绝对路径:/etc/ssh/sshd_config
#查找内容:
#获取失败.....!
#Traceback (most recent call last):
#File "1.py", line , in <module>
#raw_input()
#KeyboardInterrupt
#[root@localhost ~]# python .py
#文件绝对路径:/etc/ssh/sshd_config
#查找内容:Port
#获取失败.....!
#find 模块查询只能从左到右
#---------------------------------------------------------------------------------
最新文章
- JSon解析
- Entity Framework EF6使用 MySql创建数据库异常解决办法
- Photo Shop 修改、维护
- sql行列转换
- pygame系列_百度随心听_完美的UI设计
- [原创] zabbix学习之旅二:yum安装
- FWT 学习总结
- 多次绑定click及ajax提交常用方法
- JavaSE学习总结第10天_面向对象5
- jQuery --- 第四期 (jQuery动效)
- Python 3中bytes/string的区别
- [转]简单科普私钥、地址、助记词、Keystore的区别
- 解析 STM32 的库函数
- IIS 7安装ModSecurity实现WAF功能
- C/C++---printf/cout 从右至左压栈顺序实例详解
- 中小团队基于Docker的devops实践
- UVA 1203 - Argus(优先队列)
- OGNL是Object-Graph Navigation Language的缩写,它是一种功能强大的表达式语言
- Java进行http请求工具类代码(支持https)
- hibernate 关联关系
热门文章
- Scala语法03 - 函数
- mysql锁表机制分析
- node 笔记整理
- 学校或公司转ISP -boardband (上网公司)注意事项记录
- VMware workstation安装Windows Server 2012 R2步骤详解(附下载链接)
- 使用checked和unchecked来对整数溢出进行检测和忽略
- 大于2T的硬盘怎么分区
- 【VS开发】学习VS2010 ------ 多种类型的视图集合CTabView
- spark 1.6.0 安装与配置(spark1.6.0、Ubuntu14.04、hadoop2.6.0、scala2.10.6、jdk1.7)
- 实习第一个月总结(const关键字、条件编译、volatile关键字、#和##的作用、函数指针)