本文介绍了如何使“剪切”命令把几个连续的分隔符视为一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从基于列的,space'调整文本流中提取一定的(第四)字段。我试图使用剪切按以下方式命令:

I'm trying to extract a certain (the fourth) field from the column-based, 'space'-adjusted text stream. I'm trying to use the cut command in the following manner:

猫的text.txt |切-d-f 4

不幸的是,剪切不把多个空格为一个分隔符。我可以通过awk的管道已

Unfortunately, cut doesn't treat several spaces as one delimiter. I could have piped through awk

的awk'{printf的$ 4; }

或sed的

的sed -ES / [[:空间:]] + / / G

崩溃的空间,但我想知道是否有任何的方式来处理剪切和几个分隔符本身?

to collapse the spaces, but I'd like to know if there any way to deal with cut and several delimiters natively?

推荐答案

尝试:

cat text.txt | tr -s ' ' | cut -d ' ' -f 4

TR 手册页:


-s, --squeeze-repeats   replace each input sequence of a repeated character
                        that is listed in SET1 with a single occurrence
                        of that character

这篇关于如何使“剪切”命令把几个连续的分隔符视为一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 14:57