如何将以下破折号的新列的一切吗? [英] How to move everything following a dash to a new column?

查看:111
本文介绍了如何将以下破折号的新列的一切吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了一个文本列有破折号的文件( - )分开不同线路。我想一个破折号下的所有内容移动到一个新列。我输入文件看起来像这样:

I have a file that has a single column of text with a dash (-) separating different lines. I would like to move everything below a dash to a new column. My input file looks like this:

jim
bob
-
sally 
sue 
ed
-
bill 
-
jerry
curly
phil
-

我想我的输出文件看起来是这样的:

I would like my output file to look like this:

jim    sally    bill    jerry
bob    sue      -       curly
-      ed               phil
       -                -

感谢您提前。

推荐答案

您可以尝试一下本作名为输入 A输入文件:

You could try this for a input-file called input:

 csplit -f tempfile input '/-/+1' '{*}'; paste tempfile*

使用则csplit 我们生成一个文件中所需的输出每个列( tempfile01 ,<$ C C> tempfile02 ... $)。结果
接下来,我们合并这些临时文件。在给定的样本输入,上面命令的输出是:

With csplit we generate one file for each "column" in the desired output (tempfile01, tempfile02, ...).
Next, we merge these temporary files. With the given sample input, the output of the above command is:

jim sally   bill    jerry   
bob sue     -       curly   
-   ed              phil    
    -               -   

这可能是一个好主意,添加 RM临时文件* 做必要的清理工作。

csplit -f tempfile input '/-/+1' '{*}'; paste tempfile* > output; rm tempfile*

这篇关于如何将以下破折号的新列的一切吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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