如何使"cut"命令将顺序分隔符视为相同? [英] How to make the 'cut' command treat same sequental delimiters as one?

查看:65
本文介绍了如何使"cut"命令将顺序分隔符视为相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从基于列的空间"调整后的文本流中提取某个(第四)字段.我正在尝试通过以下方式使用cut命令:

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:

cat text.txt | cut -d " " -f 4

不幸的是,cut并未将多个空格视为一个定界符.我本来可以通过awk

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

awk '{ printf $4; }'

或sed

sed -E "s/[[:space:]]+/ /g"

折叠空格,但是我想知道是否有任何方法可以原生处理cut和几个定界符?

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

推荐答案

尝试:

tr -s ' ' <text.txt | cut -d ' ' -f4

tr手册页中:


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

这篇关于如何使"cut"命令将顺序分隔符视为相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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