我想比较两个文本文件(T2和T1)并将T2排序为t1。请你帮忙,我坚持这个。 [英] I want to compare two text files(T2 with T1)and sort T2 as t1.could you please help on this , I am stuck on this.

查看:98
本文介绍了我想比较两个文本文件(T2和T1)并将T2排序为t1。请你帮忙,我坚持这个。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< / b&>

comm -2 -3 txtp1> txtp2.Text;



我尝试过:



x

diff -a --suppress-common- lines -y a.txt b.txt> c.txt ..这会工作吗?我在谷歌搜索并尝试了可能的事情,但无法得到解决方案。

解决方案

< blockquote>我可以推荐快速彩色文本框,它有很多有趣的选项,包括差异选项和文档地图选项:用于语法突出显示的快速彩色TextBox [ ^ ]

您可以像这样使用DiffMergeSample中的类表单上的两个FastColoredTextBox控件:

使用System;使用System.Drawing 
;
使用System.Windows.Forms;
使用System.IO;

命名空间TestDiff
{
///< summary>
///显示一个表单,用于比较属性中设置的两个文件< see cref =FirstFile/>和<见cref =SecondFile/>。
/// Pavel Torgashov的FastColoredTextBoxDiffMergeSample的修改版本。
/// http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting
///< / summary>
public partial class FormCompare:Form
{
int updating;
Style greenStyle;
Style redStyle;

///< summary>
///初始化< see cref =FormCompare/>的新实例类。
///属性< see cref =FirstFile/>和<见cref =SecondFile/>必须先设置。
///< / summary>
public FormCompare()
{
InitializeComponent();
greenStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(50,Color.Lime)));
redStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(50,Color.Red)));
}

public string FirstFile {get;组; }

公共字符串SecondFile {get;组; }

private void FormCompare_Shown(object sender,EventArgs e)
{
this.CompareFiles();
}

///< summary>
///同步滚动。
///< / summary>
///< param name =sender>发件人。< / param>
///< param name =e>事件参数。< / param>
void tb_VisibleRangeChanged(object sender,EventArgs e)
{
if(updated> 0)
return;

var vPos =(发送者为FastColoredTextBox).VerticalScroll.Value;
var curLine =(sender as FastColoredTextBox).Selection.Start.iLine;

if(sender == fctb2)
UpdateScroll(fctb1,vPos,curLine);
else
UpdateScroll(fctb2,vPos,curLine);

fctb1.Refresh();
fctb2.Refresh();
}

void UpdateScroll(FastColoredTextBox tb,int vPos,int curLine)
{
if(updated> 0)
return;
//
BeginUpdate();
//
if(vPos< = tb.VerticalScroll.Maximum)
{
tb.VerticalScroll.Value = vPos;
tb.UpdateScrollbars();
}

if(curLine< tb.LinesCount)
tb.Selection = new Range(tb,0,curLine,0,curLine);
//
EndUpdate();
}

private void EndUpdate()
{
updating--;
}

private void BeginUpdate()
{
updates ++;
}

///< summary>
///比较属性中设置的文件< see cref =FirstFile/>和<见cref =SecondFile/>。
///< / summary>
private void CompareFiles()
{
if(!File.Exists(FirstFile)||!File.Exists(SecondFile))
{
MessageBox.Show(这个,请选择一个有效的文件,无效的文件);
返回;
}

fctb1.Clear();
fctb2.Clear();
Cursor = Cursors.WaitCursor;

if(Path.GetExtension(FirstFile).ToLower()==。cs)
fctb1.Language = fctb2.Language = Language.CSharp;
else if(Path.GetExtension(FirstFile)。ToLower()==。xml)
fctb1.Language = fctb2.Language = Language.XML;
else
fctb1.Language = fctb2.Language = Language.Custom;

var source1 = Lines.Load(FirstFile);
var source2 = Lines.Load(SecondFile);

source1.Merge(source2);
BeginUpdate();
流程(source1);
EndUpdate();
Cursor = Cursors.Default;
}

private void流程(行行)
{
foreach(行中的行数)
{
switch(line.state) )
{
case DiffType.None:
fctb1.AppendText(line.line + Environment.NewLine);
fctb2.AppendText(line.line + Environment.NewLine);
休息;
case DiffType.Inserted:
fctb1.AppendText(Environment.NewLine);
fctb2.AppendText(line.line + Environment.NewLine,greenStyle);
休息;
case DiffType.Deleted:
fctb1.AppendText(line.line + Environment.NewLine,redStyle);
fctb2.AppendText(Environment.NewLine);
休息;
}
if(line.subLines!= null)
Process(line.subLines);
}
}
}
}



并拨打以下表格:

 var compareForm = new FormCompare(); 
compareForm.FirstFile =XmlReplyOld.xml;
compareForm.SecondFile =XmlReply.xml;
compareForm.ShowDialog();



如果您不想编码,那么您可以在此列表中找到一个有用的实用程序:https://www.slant.co/topics/3846/ ~best-folder-file-compare-diff-tools-for-osx-linux-or-windows [ ^ ]


</b&>
comm -2 -3 txtp1>txtp2.Text;

What I have tried:

x
diff -a --suppress-common-lines -y a.txt b.txt > c.txt..is this gonna work?i have searched in the google and try the possible things but couldn't able to get the solution.

解决方案

I can recommend the Fast Colored TextBox which has a lot of interesting options, including a diff option and a document map option: Fast Colored TextBox for Syntax Highlighting[^]
You can use the classes from "DiffMergeSample" like this with two FastColoredTextBox controls on a form:

using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace TestDiff
{
    /// <summary>
    /// Show a form which compares two files set in the properties <see cref="FirstFile"/> and <see cref="SecondFile"/>.
    /// Modified version of the FastColoredTextBox "DiffMergeSample" by Pavel Torgashov.
    /// http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting
    /// </summary>
    public partial class FormCompare : Form
    {
        int updating;
        Style greenStyle;
        Style redStyle;

        /// <summary>
        /// Initializes a new instance of the <see cref="FormCompare"/> class.
        /// The properties <see cref="FirstFile"/> and <see cref="SecondFile"/> must be set first.
        /// </summary>
        public FormCompare()
        {
            InitializeComponent();
            greenStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Lime)));
            redStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Red)));
        }

        public string FirstFile { get; set; }

        public string SecondFile { get; set; }

        private void FormCompare_Shown(object sender, EventArgs e)
        {
            this.CompareFiles();
        }

        /// <summary>
        /// Synchronize scrolling.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event arguments.</param>
        void tb_VisibleRangeChanged(object sender, EventArgs e)
        {
            if (updating > 0)
                return;

            var vPos = (sender as FastColoredTextBox).VerticalScroll.Value;
            var curLine = (sender as FastColoredTextBox).Selection.Start.iLine;

            if (sender == fctb2)
                UpdateScroll(fctb1, vPos, curLine);
            else
                UpdateScroll(fctb2, vPos, curLine);

            fctb1.Refresh();
            fctb2.Refresh();
        }

        void UpdateScroll(FastColoredTextBox tb, int vPos, int curLine)
        {
            if (updating > 0)
                return;
            //
            BeginUpdate();
            //
            if (vPos <= tb.VerticalScroll.Maximum)
            {
                tb.VerticalScroll.Value = vPos;
                tb.UpdateScrollbars();
            }

            if (curLine < tb.LinesCount)
                tb.Selection = new Range(tb, 0, curLine, 0, curLine);
            //
            EndUpdate();
        }

        private void EndUpdate()
        {
            updating--;
        }

        private void BeginUpdate()
        {
            updating++;
        }

        /// <summary>
        /// Compare the files set in the properties <see cref="FirstFile"/> and <see cref="SecondFile"/>.
        /// </summary>
        private void CompareFiles()
        {
            if (!File.Exists(FirstFile) || !File.Exists(SecondFile))
            {
                MessageBox.Show(this, "Please select a valid file", "Invalid file");
                return;
            }

            fctb1.Clear();
            fctb2.Clear();
            Cursor = Cursors.WaitCursor;

            if (Path.GetExtension(FirstFile).ToLower() == ".cs")
                fctb1.Language = fctb2.Language = Language.CSharp;
            else if (Path.GetExtension(FirstFile).ToLower() == ".xml")
                fctb1.Language = fctb2.Language = Language.XML;
            else
                fctb1.Language = fctb2.Language = Language.Custom;

            var source1 = Lines.Load(FirstFile);
            var source2 = Lines.Load(SecondFile);

            source1.Merge(source2);
            BeginUpdate();
            Process(source1);
            EndUpdate();
            Cursor = Cursors.Default;
        }

        private void Process(Lines lines)
        {
            foreach (var line in lines)
            {
                switch (line.state)
                {
                    case DiffType.None:
                        fctb1.AppendText(line.line + Environment.NewLine);
                        fctb2.AppendText(line.line + Environment.NewLine);
                        break;
                    case DiffType.Inserted:
                        fctb1.AppendText(Environment.NewLine);
                        fctb2.AppendText(line.line + Environment.NewLine, greenStyle);
                        break;
                    case DiffType.Deleted:
                        fctb1.AppendText(line.line + Environment.NewLine, redStyle);
                        fctb2.AppendText(Environment.NewLine);
                        break;
                }
                if (line.subLines != null)
                    Process(line.subLines);
            }
        }
    }
}


And call the form like this:

var compareForm = new FormCompare();
compareForm.FirstFile = "XmlReplyOld.xml";
compareForm.SecondFile = "XmlReply.xml";
compareForm.ShowDialog();


If you don't want to code then you may find a utility in this list that will be useful: https://www.slant.co/topics/3846/~best-folder-file-compare-diff-tools-for-either-osx-linux-or-windows[^]


这篇关于我想比较两个文本文件(T2和T1)并将T2排序为t1。请你帮忙,我坚持这个。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆