如何剪切这些列以实现此目的?

时间:2015-12-11 04:03:49

标签: linux unix

*的Unix

我正在尝试转换的文件包含:

class Program
{
    static void Main(string[] args)
    {
        TestClass _TC;

        _TC = new TestClass();
        _TC = null;
        GC.Collect();
        GC.WaitForPendingFinalizers();
        Console.ReadKey();
    }
}

class TestClass
{
    Thread _T;
    bool _T_KeepWorking = true;
    public TestClass()
    {
        Console.WriteLine("TestClass Created.");
        _T = new Thread(new ThreadStart(Test_DoWork));
        _T.IsBackground = true;
        _T.Start();
    }

    ~TestClass()
    {
        Close();
        Console.WriteLine("TestClass Destroyed.");
    }

    public void Close()
    {
        _T_KeepWorking = false;
        if (_T.IsAlive)
        {
            _T.Join();
        }

    }

    public void Test_DoWork()
    {
        while (_T_KeepWorking)
        {
            Console.WriteLine("Test_DoWork alived.");
            Thread.Sleep(1000);
        }
    }

我正在尝试将其转换为像这样:

abc.123?zyx

我使用了命令:

123 ZYX abc

但是,当我似乎无法将最后一列复制到新文件时。 我也想知道如何利用我想要复制的最后一栏。

3 个答案:

答案 0 :(得分:4)

我认为'tr'(翻译)会更适合第一部分。 例如:

$> echo "abc.123?zyx" | tr '[.?:]' ' '
abc 123 zyx

现在要将结果字符串的最后一列转换为高位,您可以使用awk:

$> echo "abc 123 zyx" | awk '{print $1 " " $2 " " toupper($3) }'
abc 123 ZYX

因此,整个追随者应该适合你:

$> cat <file> | tr '[.?:]' ' ' | awk '{print $1 " " $2 " " toupper($3) }'

答案 1 :(得分:0)

无法评论@Ajay Kumar的回答。我正准备写@learningloop所描述的修正tr '[.?:]' ' ' < <file>

同样小的更新,因为OP要求字符串为123 ZYX abc,将答案更改为:

tr '[.?:]' ' ' < <file> | awk '{print $1 " " toupper($3) " " $2 }'

答案 2 :(得分:0)

以下是基于sed的解决方案,如果要求是内联更改文件:

sed -i 's/\(.*\)\.\(.*\)?\(.*\)/\2 \U\3 \L\1/g' <file>
相关问题