Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways that Shell scripts can read one line in a file at a time?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "Shell script to read a single line in the file what are the methods", the article explained the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Shell script to read one line in a file what are the methods?"

Write method 1:

The code is as follows:

#! / bin/bash

While read line

Do

Echo $line # here can be changed according to the actual use

Done

< urfile 写法二: 代码如下: #!/bin/bash cat urfile | while read line do echo $line done 注意:以上代码中urfile 为被读取的文件 Shell读取文本文件 方法一:通过命令获取所需内容,传递给变量 代码如下: var1=$(grep -i "^root" /etc/passwd | cut -d: -f 3 2>

/ dev/null)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report