#!/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