只需要获取所需的部分

只需要获取所需的部分

我们有一个字符串如下:

**XX_EMAIL_FILES FCP_REQID=9614696 FCP_LOGIN="APPS/sup12" FCP_USERID=5667 FCP_USERNAME="SRI" FCP_PRINTER="noprint" FCP_SAVE_OUT=Y FCP_NUM_COPIES=1 "9614556_SUP12_XX_Workflow_Stuck_AP_Invoices.csv" "/tmp_mnt2/attachments" "[email protected]" "This is the subject for the mail" "PFA for the list of Invoices that are stuck in workflow."**

我们只需将以下字符串提取到变量中:

这是邮件的主题

同样,只需将以下字符串提取到其他变量中: PFA 用于显示工作流程中停滞的发票列表。

这些并不总是相同的。字符串可能会根据用户输入的内容而有所不同。

谁能帮我了解如何使用 UNIX 命令仅获取这些字符串

问候, 博米

答案1

如果您确定字段的数量和顺序以及其中的引号,那么您可以使用cut -d\"以下方式获取必填字段:

echo 'XX_EMAIL_FILES FCP_REQID=9614696 FCP_LOGIN="APPS/sup12" FCP_USERID=5667 FCP_USERNAME="SRI" FCP_PRINTER="noprint" FCP_SAVE_OUT=Y FCP_NUM_COPIES=1 "9614556_SUP12_XX_Workflow_Stuck_AP_Invoices.csv" "/tmp_mnt2/attachments" "[email protected]" "This is the subject for the mail" "PFA for the list of Invoices that are stuck in workflow."' \
| cut -f14 -d\"
This is the subject for the mail

echo 'XX_EMAIL_FILES FCP_REQID=9614696 FCP_LOGIN="APPS/sup12" FCP_USERID=5667 FCP_USERNAME="SRI" FCP_PRINTER="noprint" FCP_SAVE_OUT=Y FCP_NUM_COPIES=1 "9614556_SUP12_XX_Workflow_Stuck_AP_Invoices.csv" "/tmp_mnt2/attachments" "[email protected]" "This is the subject for the mail" "PFA for the list of Invoices that are stuck in workflow."' \
| cut -f16 -d\"
PFA for the list of Invoices that are stuck in workflow.

awk或者如果您需要获取最后两个字段,使用方法可能更好:

echo 'XX_EMAIL_FILES FCP_REQID=9614696 FCP_LOGIN="APPS/sup12" FCP_USERID=5667 FCP_USERNAME="SRI" FCP_PRINTER="noprint" FCP_SAVE_OUT=Y FCP_NUM_COPIES=1 "9614556_SUP12_XX_Workflow_Stuck_AP_Invoices.csv" "/tmp_mnt2/attachments" "[email protected]" "This is the subject for the mail" "PFA for the list of Invoices that are stuck in workflow."' \
| awk -F\" '{ print $(NF-3) }'
This is the subject for the mail

相关内容