bashはディレクトリ内のすべてのファイルを繰り返し、各ファイルの行を繰り返します。

bashはディレクトリ内のすべてのファイルを繰り返し、各ファイルの行を繰り返します。

私は持っています

urls1.txt
urls2.txt
urls3.txt 

など。

どのようにそのディレクトリ内のすべてのファイルを繰り返し、そのファイルの各行を繰り返すことができますか?

ベストアンサー1

あなたが書いた質問に答えるには:

#!/bin/bash

for file in /path/to/files/*.txt; do
    # This will loop through each .txt file in the directory
    # setting the full file path to $file
    # I recommend adding the .txt if you know all your files
    # will have that extension otherwise the following is fine:
    # for file in /path/to/files/*; do
    while read -r line; do
        # This will loop through each line of the current file
        # and set the full line to the $line variable
        command "$line"
    done < "$file"
done

コード内のコメントに記載されています。

おすすめ記事