Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-03 09:25:17 11月15日 Update

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)

Tags: Content files methods code one line scripts variables learning writing commands pipes problems processing testing output size actually that is ideas situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology vpn Docker MariaDB