【问题标题】:Place word index next to each word in a paragraph of text在一段文本中的每个单词旁边放置单词索引
【发布时间】:2020-11-06 13:52:55
【问题描述】:

有没有办法使用 grepsedawk 将每个单词的索引放在单词旁边(或者有没有内置此功能的软件)?

例如,给定以下文本:

"I love the power of Grep SED and AWK, but I am no good at using it"

我想要这个:

"I(1) love(2) the(3) power(4) of(5) Grep(6) SED(7) and(8) AWK,(9) but(10) I(11) am(12) no(13) good(14) at(15) using(16) it(17)"

澄清:"I" 排在第一位得到"(1)""it" 排在最后17 个字得到"(17)"

【问题讨论】:

  • 为什么要在此处重新发布,biostars 的答案是否不明确/足够? biostars.org/p/449890
  • 接近投票者,请重新考虑,帖子足够清晰。

标签: awk text sed grep


【解决方案1】:

不是计数而是索引号,

$ echo "I ..."  | awk '{for(i=1;i<=NF;i++) $i=$i "(" ++c ")"}1'

I(1) love(2) the(3) power(4) of(5) Grep(6) SED(7) and(8) AWK,(9) but(10) I(11) am(12) no(13) good(14) at(15) using(16) it(17)

【讨论】:

    猜你喜欢
    • 2015-09-18
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    • 1970-01-01
    相关资源
    最近更新 更多