sedコマンドでエラーが発生しました

sedコマンドでエラーが発生しました

次の形式のファイルがあります。c1234.$pid.$date

私はそれからpidを取得したいと思います。私がしたことは、これらすべてのファイル名を結果ファイルに書き込んで実行することでした。

cat result.$$ | for x in `sed -e 's/..*8\.//g'`

しかし、エラーが発生しました。

syntax error at line 12 : ``' unmatched

ここに問題がありますか?

ベストアンサー1

ファイルを一覧表示し、そのファイルに対してforループを実行し、各反復から$ pidを抽出できます。

#!/bin/bash
# Go to the path where files are present
cd /path/to files
# Initiate a for loop
for file in `ls`
do
    #Use '.' as a field separator and pull out the second column.
    cat "$file" | awk -F'.' '{print $2}'
done

おすすめ記事