0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Shell]ディレクトリのあるファイル名の先頭がEP802で始まるプロパティファイルの特定のキーだけを順番に取得して表示

Posted at
EP802_test.properties
SEND_URL=http://localhost:8080/keys
TIMEOUT=1000
EP802_test2.properties
SEND_URL=http://localhost:8080/keys
TIMEOUT=1000
test3.sh
#!/bin/bash

# 設定
TARGET_DIR="./" # 検索するディレクトリ
PREFIX="EP802"  # ファイル名の先頭
KEY="SEND_URL" # 取得するキー

# ディレクトリ内の対象ファイルを順に処理
for file in "$TARGET_DIR"/$PREFIX*.properties; do
  # ファイルが存在しない場合の処理
  if [ ! -f "$file" ]; then
    echo "No files found with prefix $PREFIX in $TARGET_DIR"
    exit 1
  fi

  # プロパティファイルからキーの値を取得
  VALUE=$(grep "^$KEY=" "$file" | cut -d'=' -f2)

  # キーが見つからなかった場合
  if [ -z "$VALUE" ]; then
    echo "Key $KEY not found in $file"
    continue
  fi

  # 結果を表示
  echo "File: $file, Key: $KEY, Value: $VALUE"
done
$ chmod +x test3.sh
$ ./test3.sh

File: .//EP802_test.properties, Key: SEND_URL, Value: http://localhost:8080/keys
File: .//EP802_test2.properties, Key: SEND_URL, Value: http://localhost:8080/keys2
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?