Grep for windows

时间:2016-08-01 13:44:36

标签: cmd grep findstr

New.txt包含

apple
orange
banana
grape
lemon

New.txt包含

grep

我可以使用grep -Fxvf Old.txt New.txt > difference.txt 命令访问添加到difference.txt的新内容。

grape
lemon

现在,findstr /rvc:Old.txt New.txt > difference.txt 包含

Old.txt

在Windows中,我尝试过

protected virtual void CRCase_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated InvokeBaseHandler)
{
    if (InvokeBaseHandler != null)
        InvokeBaseHandler(cache, e);
    var row = e.Row as CRCase;
    var oldRow = e.OldRow as CRCase;
    CRCaseExt rowExt = PXCache<CRCase>.GetExtension<CRCaseExt>(row);

    if (row == null || oldRow == null) return;

    if (row.OwnerID == null)
    {
        row.AssignDate = null;
        row.SLAETA = null;
    }
    else if (oldRow.OwnerID == null)
    {
        row.AssignDate = PXTimeZoneInfo.Now;
        if (row == null || row.AssignDate == null) return;

        if (row.ClassID != null && row.Severity != null)
        {
            var severity = (CRClassSeverityTime)PXSelect<CRClassSeverityTime,
                            Where<CRClassSeverityTime.caseClassID, Equal<Required<CRClassSeverityTime.caseClassID>>,
                            And<CRClassSeverityTime.severity, Equal<Required<CRClassSeverityTime.severity>>>>>
                            .Select(Base, row.ClassID, row.Severity);
            if (severity != null && severity.TimeReaction != null)
            {
                row.SLAETA = ((DateTime)row.AssignDate).AddMinutes((int)severity.TimeReaction);
            }
        }
        if (row.Severity != null && row.ContractID != null)
        {
            var template = (Contract)PXSelect<Contract, Where<Contract.contractID, Equal<Required<CRCase.contractID>>>>.Select(Base, row.ContractID);
            if (template == null) return;
            var sla = (ContractSLAMapping)PXSelect<ContractSLAMapping,
                    Where<ContractSLAMapping.severity, Equal<Required<CRCase.severity>>,
                    And<ContractSLAMapping.contractID, Equal<Required<CRCase.contractID>>>>>
                    .Select(Base, row.Severity, template.TemplateID);
            if (sla != null && sla.Period != null)
            {
                row.SLAETA = ((DateTime)row.AssignDate).AddMinutes((int)sla.Period);
            }
        }
    }
}

找到差异,但它也追加{{1}}的内容。如何在Windows中编写等效命令?

2 个答案:

答案 0 :(得分:6)

您可以将DOS findstr与以下标志一起使用: -

/v   : Prints only lines that do not contain a match.
/g: file   : Gets search strings from the specified file.

命令如下: -

C:\Users\dude\Desktop>findstr /v /g:Old.txt New.txt >difference.txt

现在使用type命令检查文件输出;相当于cat中的Linux,我们看到: -

C:\Users\dude\Desktop>type difference.txt
grape
lemon

答案 1 :(得分:2)

除非限制在PC上安装任何内容,否则考虑安装类似* nix的工具(如GnuWin32)的端口并继续使用grep。