【问题标题】:Uppercase the second column of a text file in Unix大写 Unix 中文本文件的第二列
【发布时间】:2021-05-05 22:11:35
【问题描述】:

我有一个包含三列的 txt 文件。第二列如下(每个字母为该列的一行):

  1. 一个
  2. t
  3. c
  4. 一个
  5. 一个
  6. t

我需要在 Unix 中将第二列大写,但不知道如何(应该使用命令:| tr [a-z] [A-Z]。您能帮帮我吗?

【问题讨论】:

    标签: unix uppercase


    【解决方案1】:
     awk '{$2 = toupper($2)}1' input-file
    

    很难为此使用tr,因为tr 会不加选择地更改输入的每个字符。但是你可以使用tr 来做大写,比如:

    awk '{c="tr [a-z] [A-Z]"; printf "%s%c", $1, OFS;
        printf "%s", $2 | c; close c; print OFS $3}' input-file
    

    或者,如果您使用 bash 并且输入文件由制表符分隔:

    paste <(cut -f 1 input) <(tr [a-z] [A-Z] < input | cut -f 2) <(cut -f 3 input)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-23
      • 1970-01-01
      • 2019-08-23
      • 2013-06-22
      • 1970-01-01
      相关资源
      最近更新 更多