当前位置:网站首页>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是按行读取,如果行内文字有空格,则分开读取,即一次读取一个字符串
边栏推荐
- 最长递增子序列
- PHP starts OpenSSL and reports OpenSSL support=> disabled (install ext/openssl)
- Will your company choose to develop data center?
- Recent learning and update plan
- OpenJudge NOI 1.13 18:Tomorrow never knows?
- Question bank and answers for 2022 melting welding and thermal cutting operation certificate examination
- Link list of high frequency written interview question brushing summary (distribution explanation & code annotation)
- 数据库唯一索引和普通索引的区别?
- Three special data types, day3 and redis (geographic location, cardinality statistics and bitmap scene usage)
- Prophet
猜你喜欢

When the interviewer opens his mouth, he comes to compose. Is this the case now?

CPT 102_ LEC 15

CPT 102_LEC 16

怎样简洁明了地说清楚产品需求?

Link list of high frequency written interview question brushing summary (distribution explanation & code annotation)
![[C language classic]: inverted string](/img/f3/e6f37b852d22d395314628b73c9be3.jpg)
[C language classic]: inverted string

从绿联冲刺IPO,看手机配件市场沉浮录

Explication du cours de graphacademy: neo4j Graph Data Science Foundation

軟件測試英語常見詞匯

What is ttfb
随机推荐
【面试题 17.04. 消失的数字】
How to state clearly and concisely the product requirements?
Navicat premium 15 tool is automatically deleted by anti-virus protection software solution
How to handle error code 30204-44 when installing office 2016 in win10?
AOSP ~ modify default volume
判断一串数字是否是快速排序某一次的结果
银行选择电子招标采购的必要性
Fundamentals of deep learning [4] build easyocr and carry out simple character recognition from 0
【冒泡排序的实现】
Android WiFi hide SSID configuration method
RS232/RS485转4G DTU 上传基于Modbus协议的温湿度传感器数据到远程TCP服务器
AOSP - Developer mode is enabled by default
怎样确保消息的可靠性投递?
学习太极创客 — ESP8226 (二)
Problèmes de classe d'outils JDBC
Cmake common commands
Arduino Uno接JQ8900-16p语音播报模块
Graphacademy course explanation: Fundamentals of neo4j graph data science
数据库唯一索引和普通索引的区别?
求MySQL先按大于等于当前时间升序排序,再按小于当前时间降序排序