特定の列番号1と列番号2のファイルを繰り返します。

特定の列番号1と列番号2のファイルを繰り返します。

1000行と2列を含むtest.txtファイルがあります。

am-rls-dev am-nexus
am-rls-dev cancel-ppd-nexus
am-rls-dev h2h-autodebet-token-nexus
am-rls-dev h2h-autodebet-transact-nexus
am-rls-dev h2h-onlinepaymentmuf-nexus
am-rls-dev preterm-nexus
am-rls-dev received-trade-ho-nexus
chatboot-api-dev chatbot-api-nexus
chatboot-api-dev chatbot-be-nexus
cis-rls-dev cif-cis-nexus
cis-rls-dev cis-nexus
cis-rls-dev custhandling-cis-nexus
cis-rls-dev rpt-handling-nexus

データが二重スペースで区切られ、後にスペースが続く場合:

am-rls-dev  am nexus
am-rls-dev  cancel ppd nexus
am-rls-dev  h2h autodebet token nexus
am-rls-dev  h2h autodebet transact nexus
am-rls-dev  h2h onlinepaymentmuf nexus

最初の列は名前空間で、2番目の列はビルド構成であるとします。私の質問は、次のループでどのように印刷できるかです。

echo this namespace is: $namespace and this buildconfig is: $buildconfig
echo this namespace is: $namespace and this buildconfig is: $buildconfig
echo this namespace is: $namespace and this buildconfig is: $buildconfig
echo this namespace is: $namespace and this buildconfig is: $buildconfig
echo this namespace is: $namespace and this buildconfig is: $buildconfig

ベストアンサー1

使用read組み込み1行を読み、(オプションで)単語に分割します。

while read -r namespace buildconfig ignored; do
  echo "this namespace is: $namespace and this buildconfig is: $buildconfig"
done <test.txt

行を並列に処理するには、次のものを使用できます。GNUパラレル

parallel '
  line={};
  a=($=line); namespace=$a[1] buildconfig=$a[2];
  echo "this namespace is: $namespace and this buildconfig is: $buildconfig"'

おすすめ記事