LoginSignup
0
2

More than 5 years have passed since last update.

Bash > 複数の(空白あり)テキストに対するsed変換処理 > sed文字列の生成まで > 複数行のstring list処理

Last updated at Posted at 2017-08-29
動作環境
ideone (bash 4.4.5)

やろうとしていたこと

A B C
D E F
G    H I

上記の文字列(3種類)を持つ行に対して以下の処理を行う

  • 行頭の空白を取る
  • ###をつける (Markdown ヘッダ)

code

sedコマンド文字列生成まで

#!/bin/bash

targets="A B C
D E F
G    H I"

while read -r line
do
   cmd="sed 's/ *$line/###$line/g'"
   echo "$cmd"
done <<< $targets
run
sed 's/ *A B C/###A B C/g'
sed 's/ *D E F/###D E F/g'
sed 's/ *G    H I/###G    H I/g'

参考

targetsを読みこむ処理に関しては、以下を参考にしました。
https://stackoverflow.com/questions/8880603/loop-through-an-array-of-strings-in-bash

answered Oct 16 '16 at 21:59
Jamie

ファイルを読む場合はこちらのコメントを参照。
bash > 行を取り出す > headとtailの組合せ > コメントに改良案あり

0
2
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
2