0

编辑

我有一个包含字符串行的文件

mediafire.com/?a6o37kfc7m68dri

注意:媒体火上的那个文件实际上是“logs.out”,当我上传它时,我刚刚将它重命名为logs.txt。

示例内容:(logs.out)

BIF in bif_init> login successful
BIF in dbInit> INFO: DB status:20,successful
BIF in dbInit> INFO: get the fileName need be query DB. Size(0) 
BIF in dbInit> INFO: get the fileName need be query DB. Size(30) 
BIF in modInit> INFO: modInit finished
BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/4302253 
BIF in setInputTag> set input tag value, name/value:bill_ref_no/199863752 
BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 
BIF in setInputTag> set input tag value, name/value:DISPUTE_AMOUNT/0 
BIF in setInputTag> set input tag value, name/value:NOD_FLAG/0 
BIF in setInputTag> set input tag value, name/value:OUTSTANDING_BALANCE/12904
BIF in setInputTag> set input tag value, name/value:TOTAL_DUE/12904 
BIF in run> INFO: updateParameterValues finished
BIF in getFile> INFO: Feed file(/arbordata/feedfile/PS-M07-1205-20130807-20130911-201711-1-bif01.DAT) for current invoice
BIF in insertNewFile> m_pcurFileNameAttr->file_seq_no:(1)  
BIF in insertNewFile> INFO:Output fileHeader(000020130911201711
    ) to feedfile,successful 
BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/4302253 
BIF in setInputTag> set input tag value, name/value:bill_ref_no/199863752 
BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 
BIF in setInputTag> set input tag value, name/value:DISPUTE_AMOUNT/0 
BIF in setInputTag> set input tag value, name/value:NOD_FLAG/0 
BIF in setInputTag> set input tag value, name/value:OUTSTANDING_BALANCE/12904
BIF in setInputTag> set input tag value, name/value:TOTAL_DUE/12904 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLZIPCODE) into ACCT map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLEDACCOUNTNUMBER) into ACCT map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLNUMBER) into ACCT map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLNUMBERRESETS) into ACCT map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBER) into SI inherited_map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBERRESET) into SI inherited_map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(DEFAULTEXTERNALID) into SI inherited_map 
BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=2813096,0
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBER) into SI inherited_map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBERRESET) into SI inherited_map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(DEFAULTEXTERNALID) into SI inherited_map 
BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=13415970,0
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBER) into SI inherited_map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBERRESET) into SI inherited_map
BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/2726650 
BIF in setInputTag> set input tag value, name/value:bill_ref_no/190155402 
BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 
BIF in setInputTag> set input tag value, name/value:DISPUTE_AMOUNT/0 
BIF in setInputTag> set input tag value, name/value:NOD_FLAG/0 
BIF in setInputTag> set input tag value, name/value:OUTSTANDING_BALANCE/164888
BIF in setInputTag> set input tag value, name/value:TOTAL_DUE/164888 
BIF in run> INFO: updateParameterValues finished
BIF in getFile> INFO: Feed file(/arbordata/feedfile/PS-M02-1204-20130602-20130911-201711-1-bif01.DAT) for current invoice
BIF in insertNewFile> m_pcurFileNameAttr->file_seq_no:(1)  
BIF in insertNewFile> INFO:Output fileHeader(000020130911201711
) to feedfile,successful 
BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/2726650 
BIF in setInputTag> set input tag value, name/value:bill_ref_no/190155402 
BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 
BIF in setInputTag> set input tag value, name/value:DISPUTE_AMOUNT/0 
BIF in setInputTag> set input tag value, name/value:NOD_FLAG/0 
BIF in setInputTag> set input tag value, name/value:OUTSTANDING_BALANCE/164888
BIF in setInputTag> set input tag value, name/value:TOTAL_DUE/164888 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLZIPCODE) into ACCT map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLEDACCOUNTNUMBER) into ACCT map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLNUMBER) into ACCT map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLNUMBERRESETS) into ACCT map 
BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map 

唯一想要的行:

BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/4302253
BIF in setInputTag> set input tag value, name/value:bill_ref_no/199863752 
BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1

BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/4302253 
BIF in setInputTag> set input tag value, name/value:bill_ref_no/199863752 
BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 

BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/2726650 
BIF in setInputTag> set input tag value, name/value:bill_ref_no/190155402 
BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 

BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/2726650 
BIF in setInputTag> set input tag value, name/value:bill_ref_no/190155402 
BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 

我想将它输出到格式如下的文件中:(水平和管道分隔符)

BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/4302253|BIF in setInputTag> set input tag value, name/value:bill_ref_no/199863752|BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 
BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/4302253|BIF in setInputTag> set input tag value, name/value:bill_ref_no/199863752|BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1
BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/2726650|BIF in setInputTag> set input tag value, name/value:bill_ref_no/190155402|BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1
BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/2726650|BIF in setInputTag> set input tag value, name/value:bill_ref_no/190155402|BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 

请帮助我:(我想创建 .sh 文件,它将在 PuTTy 上运行

执行此代码时,它正在工作

sed -n -e '/value:ACCOUNT_NO/{N;N;s/..\n\(.\)/|\1/g;p;}' logs.out> OUPUT_logs.out

但当

sed -n -e '/value:ACCOUNT_NO/{N;N;s/..\n\(.\)/|\1/g;p;}' logs.out> OUPUT_logs.txt

每条记录之间都有“空白线”。

4

3 回答 3

0

您正在 PuTTY 上运行它。我猜这是logs.txt你的Windows版本。首先dos2unix在日志文件上运行命令,然后sh按照我写的那样执行该文件:

dos2unix logs.txt

这是a.sh. 的内容a.sh如下:

#!/bin/sh  
awk '/ACCOUNT_NO/,/resets\/1/ {printf $0" "}' logs.txt | awk '{gsub(/resets\/1/,"resets/1\n");print}' | sed -e 's/ BIF/|BIF/g' -e 's/^ |BIF/BIF/g'

在执行之前更改文件的权限。

chmod a+x ./a.sh

然后执行文件

./a.sh > new_file.txt
于 2013-09-17T02:57:10.063 回答
0

制作一个名为的 shell 脚本,例如summarise_accounts.sh

#!/bin/bash
exec paste -d'|' <(grep value:ACCOUNT_NO "$1") <(grep value:bill_ref_no "$1") <(grep value:bill_ref_resets "$1")

使其可执行(chmod +x summarise_accounts.sh),然后像这样运行它:

./summarise_accounts.sh logs.txt >account_summary.txt

当然,您可以在命令行上更改文件名。

于 2013-09-17T00:49:19.397 回答
0
sed -n -e '/value:ACCOUNT_NO/{N;N;s/\n/|/g;p;}' logs.txt > outfile.txt

编辑:

我已经修改了上面的命令以将输出重定向到一个文件,但更重要的是我们更正了输出。我已经使用logs.txt您提供的示例测试了该命令;我对您的系统了解得不够多,无法说明为什么它在那里不起作用,所以让我们进行实验。尝试这个:

sed -n -e '/value:ACCOUNT_NO/p' logs.txt

输出是什么?

编辑:

到目前为止,一切都很好。现在试试这个:

sed -n -e '/value:ACCOUNT_NO/{p;}' logs.txt

一样的输出?

编辑:

好的!现在:

sed -n -e '/value:ACCOUNT_NO/{N;N;p;}' logs.txt

输出是什么?

编辑:

最后一步,我们重定向到outputfile.txt并删除换行符。正如@ChrisJester-Young 所说,我们可以在同一步骤中删除尾随空格:

sed -n -e '/value:ACCOUNT_NO/{N;N;s/ \n/|/;p;}' logs.txt > outputfile.txt

编辑

试试这个,我们称之为代码 6

sed -n -e '/value:ACCOUNT_NO/{N;N;s/..\n/|/g;p;}' logs.txt > outputfile.txt

编辑:

问题是你logs.txt有 DOS 风格的行尾。我认为 Code 6 将它们更改为 UNIX 样式,并且 ultra edit 警告您它们很奇怪。试试这个(代码 7):

sed -n -e '/value:ACCOUNT_NO/{N;N;s/..\n\(.\)/|\1/g;p;}'
于 2013-09-17T00:52:45.190 回答