当前位置:网站首页>Shell 按行读取文件
Shell 按行读取文件
2022-06-11 02:36:00 【墨痕诉清风】
背景
做批量文件替换、删除时,读取文件内容已写好的文件名,存入数组中,遍历进行for循环批量替换。
写法一
#!/bin/bash
#描述:
# while循环读行操作
while read line
do
echo $line
done < filename写法二(这个循环在动态添加数组后数组中数据丢失)
#!/bin/bash
#描述:
# cat后读行操作
cat filename | while read line
do
echo $line
done写法三
#!/bin/bash
#描述:
# for循环读行操作,与while读行有区别
for line in `cat filename`
do
echo $line
done注
for循环读行操作,与while读行的区别
while是完全按行读取,不管行内有多少段文字
for是按行读取,如果行内文字有空格,则分开读取,即一次读取一个字符串
边栏推荐
- Problèmes de classe d'outils JDBC
- 从绿联冲刺IPO,看手机配件市场沉浮录
- Use of CIN and cout
- 第七章 常用的协议简介(1)
- [implementation of bubble sorting]
- The new colleague asked me what "where 1=1" means???
- Application of the remote acquisition IOT gateway of the Bashir trough flowmeter in open channel flow monitoring
- CPT 102_ LEC 18
- [C language classic]: inverted string
- CPT 102_ LEC 20
猜你喜欢

Graphacademy course explanation: Fundamentals of neo4j graph data science

Link list of high frequency written interview question brushing summary (distribution explanation & code annotation)

How to state clearly and concisely the product requirements?

CPT 102_LEC 15

How to handle error code 30204-44 when installing office 2016 in win10?

2022年熔化焊接与热切割操作证考试题库及答案
![[MySQL 45 -10] Lesson 10 how MySQL selects indexes](/img/eb/dbde2852a89ece383266da1aeea862.jpg)
[MySQL 45 -10] Lesson 10 how MySQL selects indexes

Uni app - one click access to user information

CPT 102_LEC 17

Question bank and answers for 2022 melting welding and thermal cutting operation certificate examination
随机推荐
[big guy show] aiops in the eyes of Borui data, choosing the right track and the right people
Flink开发环境搭建及WordCount
Prophet
[189. rotation array]
The two request sessionids of the same user are inconsistent ----- record the problem
银行选择电子招标采购的必要性
Win10 安装Office 2016出现错误代码30204-44怎么处理?
Problèmes de classe d'outils JDBC
出栈序列是否是入栈序列
GraphAcademy 课程讲解:《Neo4j 图数据科学基础》
位置数据融合表3
Blue Bridge Cup_ Xiao Lan eats candy_ Pigeon nest principle / drawer principle
20220610 Friday
【189. 轮转数组】
JS memory leak
同一个用户的两次请求SessionId竟然不一致-----记录问题
[Fibonacci series]
Write my Ini configuration file error
[MySQL 45 -10] Lesson 10 how MySQL selects indexes
[C language classic]: inverted string