简体   繁体   English

从Shell脚本中的RTF文件中提取信息

[英]Extract information from RTF file in shell script

We have many RTF files which we need to upload in Oracle EBS to their respective category. 我们有许多RTF文件,需要在Oracle EBS中上载到各自的类别。 To do so we need to read some info stored in Document Properties of RTF file. 为此,我们需要阅读一些存储在RTF文件的文档属性中的信息。 These fields are Title, Subject, Author, Company and Category. 这些字段是标题,主题,作者,公司和类别。

When we open a RTF file in notepad, we can see this info but not sure how to extract it using linux command. 当我们在记事本中打开RTF文件时,我们可以看到此信息,但不确定如何使用linux命令将其提取。 Using grep wasn't very successful. 使用grep并不是很成功。

I am pasting here part of RTF file which holds this info 我在这里粘贴包含此信息的RTF文件的一部分

\mwrapIndent1440\mintLim0\mnaryLim1}{\info**{\title ^XXSLS_GBL_ORDACK^}****{\subject XXSLS}****{\author ^es_ES,es_FR,ES_IT,ES_de^}**{\doccomm $Header: XXSLS_GBL_ORDACK_ES_ES.rtf $}
{\operator }{\creatim\yr2012\mo11\dy11\hr14\min3}{\revtim\yr2013\mo3\dy2\hr10\min43}{\version24}{\edmins361}{\nofpages4}{\nofwords725}{\nofchars14202}{\*\manager }{\*\company }**{\*\category ^BD^}**{\nofcharsws14898}
{\vern32773}}{\*\userprops {\propname _DocHome}\proptype3{\staticval -974575144}}{\*\xmlnstbl {\xmlns1 http://schemas.microsoft.com/office/word/2003/wordml}}\paperw11850\paperh18144\margl851\margr851\margt851\margb0\gutter0\ltrsect

Can someone please suggest how we can extract this info as follows: 有人可以建议我们如何提取此信息,如下所示:

Title=^XXSLS_GBL_ORDACK^
Subject=XXSLS
Author=^es_ES,es_FR,ES_IT,ES_de^
Category=^BD^

Grep can do it with the -E (advanced regex) flag and -o (only matching output) flag. Grep可以使用-E(高级正则表达式)标志和-o(仅匹配输出)标志来实现。

 title=`grep -oE 'title [^\}]+' file.rtf | sed 's/title //g'`
 echo "title=$title"
 subject=`grep -oE 'subject [^\}]+' file.rtf | sed 's/subject //g'`
 echo "subject=$subject"
 author=`grep -oE 'author [^\}]+' file.rtf | sed 's/author //g'`
 echo "author=$author"
 category=`grep -oE 'category [^\}]+' file.rtf | sed 's/category //g'`
 echo "category=$category"

I get 我懂了

title=^XXSLS_GBL_ORDACK^
subject=XXSLS
author=^es_ES,es_FR,ES_IT,ES_de^
category=^BD^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM