python和shell获取文本内容的方法
作者:KingNotJustAName 时间:2023-06-20 05:42:35
这两天搞脚本,花费不少时间。
Python和Shell都可以获取文本内容,网上许多资料介绍的都不具体。简单的使用Python和Shell写了脚本。
做一些笔记沉淀一下。
1、Python实现:
#-*- encoding:UTF-8 -*-
filehandler = open('f.txt','r') #以读方式打开文件,rb为二进制方式(如图片或可执行文件等)
print filehandler.read() #读取整个文件
filehandler.close() #关闭文件句柄
2、Shell实现:
#!/bin/bash
#定义了要读取文件的路径
MY_FILE=/usr/loca/hrnm/switch_info
while read MY_LINE
do
#输出读到的每一行的结果
echo $MY_LINE
done < $MY_FILE
来源:https://blog.csdn.net/KingOfOnePiece/article/details/55212172
标签:python,shell,内容
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Golang开发之接口的具体使用详解
2024-02-10 20:32:47
Mysql数据库手动及定时备份步骤
2024-01-27 10:43:15
![](https://img.aspxhome.com/file/2023/4/69854_0s.png)
如何用 Python 制作一个迷宫游戏
2022-03-29 20:44:07
![](https://img.aspxhome.com/file/2023/5/92065_0s.gif)
将函数的实际参数转换成数组的方法
2024-04-18 09:59:56
python timestamp和datetime之间转换详解
2021-02-07 11:17:51
Golang语言实现gRPC的具体使用
2024-05-05 09:26:19
![](https://img.aspxhome.com/file/2023/1/128701_0s.jpg)
python jenkins 打包构建代码的示例代码
2022-10-05 02:22:02
一场关于YUI3/jQuery的精彩辩论
2010-11-11 12:50:00
利用numpy+matplotlib绘图的基本操作教程
2021-01-26 11:14:31
![](https://img.aspxhome.com/file/2023/8/133778_0s.png)
JavaScript中常见的几种获取元素的方式
2023-07-13 07:46:12
![](https://img.aspxhome.com/file/2023/7/55937_0s.jpg)
Python3 如何开启自带http服务
2023-07-27 14:33:46
![](https://img.aspxhome.com/file/2023/1/63911_0s.jpg)
女装类视觉设计分享
2009-10-30 18:36:00
![](https://img.aspxhome.com/file/UploadPic/200910/30/1256637795938-73s.jpg)
jupyter notebook快速入门及使用详解
2023-07-17 07:48:57
![](https://img.aspxhome.com/file/2023/4/120584_0s.png)
python3在同一行内输入n个数并用列表保存的例子
2023-05-18 04:10:47
Python datetime模块的使用示例
2022-10-20 22:33:39
![](https://img.aspxhome.com/file/2023/5/124095_0s.png)
python编程开发之类型转换convert实例分析
2023-03-24 05:48:06
谈谈JavaScript中super(props)的重要性
2024-04-30 09:56:11
VMware中linux环境下oracle安装图文教程(一)
2024-01-28 07:10:36
![](https://img.aspxhome.com/file/2023/6/65656_0s.jpg)
Django实现支付宝付款和微信支付的示例代码
2021-01-31 10:16:29
![](https://img.aspxhome.com/file/2023/0/121130_0s.png)
在Python的Flask框架中使用模版的入门教程
2021-09-14 04:57:59