Unix,分离表 [英] Unix, Separate-table

查看:30
本文介绍了Unix,分离表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在这两个词之间放置空格而不影响其他词.

如您所见,我在此处按年龄递减顺序调整了两列.我想将单词 NameAge 分开,以便它们中的每一个都位于一个单元格及其对应的列中.我该如何解决这个问题?

解决方案

下面的命令在小写字母和大写字母之间插入空格.

 sed '1s/\([a-z]\)\([A-Z]\)/\1 \2/g' orig.txt >拆分.txt

orig.txt:

<前>姓名年龄鲍勃 90莎拉 76罗素 49凯特 21

split.txt

<前>姓名年龄鲍勃 90莎拉 76罗素 49凯特 21

sed 表达式中的 1 只影响标题,根据@jm666 的建议

sed '1s/-//g' orig.txt >拆分.txt

原来 orig.txt 看起来像这样:

<前>姓名-人号-年龄鲍勃 1 90莎拉 2 76罗素 3 49凯特 4 21

split.txt

<前>姓名人员编号年龄鲍勃 1 90莎拉 2 76罗素 3 49凯特 4 21

How to put space between these two words without affecting other words.

As you can see, I have two columns here adjusted in decreasing order of age. I want to separate the word NameAge so that each of them be in a cell and its corresponding column. How can I solve this problem?

解决方案

The command below insert space between lowercase letter and uppercase letter.

 sed '1s/\([a-z]\)\([A-Z]\)/\1 \2/g' orig.txt > split.txt

orig.txt:

NameAge
Bob      90
Sarah    76
Russel   49
Kate     21

split.txt

Name Age
Bob      90
Sarah    76
Russel   49
Kate     21

EDIT: 1 in the sed expression to affect only header, per suggested by @jm666

EDIT2:

sed '1s/-/ /g' orig.txt > split.txt

Turned out that orig.txt looks like this:

Name-PersonNumber-Age
Bob      1 90
Sarah    2 76
Russel   3 49
Kate     4 21

split.txt

Name PersonNumber Age
Bob      1 90
Sarah    2 76
Russel   3 49
Kate     4 21

这篇关于Unix,分离表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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