テキストファイルのテキストの末尾に.pdfを追加する - bash

テキストファイルのテキストの末尾に.pdfを追加する - bash
#!/bin/bash
#read the text line by line and cut off the extension
while read filenames ; do
    dataset=$filenames
    nameis=${dataset%.*}
    echo "$nameis" >> /infanass/dev/admin/test/parsed.txt
done < /infanass/dev/admin/test/tobeparsed.txt #location where file names w/ extensions are 

while read line ; do
    grep "^$line$" /infanass/dev/admin/test/parsed.txt >>matches.txt
done < /infanass/dev/admin/test/file1.txt

2つのファイル間のテキストを比較し、一致するとmatch.txtに送信されます。 match.txtに送信された値には拡張子がありません(名前のみ)。ファイルを送信するときは、すべてのファイルに.pdfを追加したいと思います。 Hits match.txtは誰にありますか?どんなアイデアがありますか?

ベストアンサー1

最後のwhileループを次に変更します。

while read line 
do
    if grep -q "^$line$" /infanass/dev/admin/test/parsed.txt
    then
        echo "${line}.pdf" >>matches.txt
    fi
done < /infanass/dev/admin/test/file1.txt

ちなみにファイルにスクリプトを書くと、ループでセミコロンを使う必要はありません。端末の1行に複合コマンドを作成する場合にのみ必要です。

おすすめ記事