将命令输出存储到 Bash 变量中

将命令输出存储到 Bash 变量中
#!/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

相关内容