Creating an array from a text file in Bash

前端 未结 6 1865
小鲜肉
小鲜肉 2020-11-22 10:25

A script takes a URL, parses it for the required fields, and redirects its output to be saved in a file, file.txt. The output is saved on a new line each time a fie

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 11:25

    You can simply read each line from the file and assign it to an array.

    #!/bin/bash
    i=0
    while read line 
    do
            arr[$i]="$line"
            i=$((i+1))
    done < file.txt
    

提交回复
热议问题