当前位置:网站首页>Shell reads files by line

Shell reads files by line

2022-06-11 03:01:00 Ink mark vs. breeze

background

Do batch file replacement 、 deleted , Read the file name written in the file content , Put in an array , Traversal for Cyclic batch replacement .

Writing a

#!/bin/bash

# describe :
#       while Cyclic line reading operation 

 
while read line
do
  echo $line
done < filename

Write two ( This loop loses data in the array after dynamically adding the array )

#!/bin/bash

# describe :
#      cat Post read line operation 
 
 
cat filename | while read line
do
  echo $line
done

Write three

#!/bin/bash

# describe :
#      for Cyclic line reading operation , And while There is a difference between reading lines 
 
 
for line in `cat filename`
do
  echo $line
done

notes

for Cyclic line reading operation , And while The difference between reading lines

while Is to read completely by line , No matter how many paragraphs there are in the line

for Yes, read by line , If there are spaces in the text in the line , Read separately , That is, read one at a time character string

原网站

版权声明
本文为[Ink mark vs. breeze]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110236411106.html