#!/bin/bash
NEW_TEXT="if failed Send to Karn Kumarl"
OLD_FILE="$(awk '{print $1}' RMANJOBS | while read JB;do autorep -j $JB -q;done | egrep "^/|^insert_job|^description" | sed '0~3 a\\')"
NEW_FILE="MRMANJOBS"
AWK='''
#.. Get new text from the shell variable.
BEGIN { NewText = " " ENVIRON["TXT"] "\042"; }
#.. If this line needs the fix, substitute the text.
/^description:.* [Ii]f failed / { sub (/ [Ii]f failed .*$/, NewText); }
#.. Print all lines, whether fixed or not.
{ print; }
'''
TXT="${NEW_TEXT}" awk "${AWK}" "${OLD_FILE}" > "${NEW_FILE}"
コマンド出力を変数にソートする必要があります。 OLD_FILEに合わないからです。
答え1
#!/bin/bash
while read JB last
do
autorep -j $JB -q
done < RMANJOBS |
sed -rn "/^\/|^insert_job|^description/{
s/(description:.* [Ii]f failed )[^"]*/\1Send to Karn Kumarl/
s/insert/update/
p
}" |
sed '0~3 G' > MRMANJOBS