0

My file is as below file name = test

1    abc
2    xyz
3    pqr

How can i convert second column of file in upper case without using awk or sed.

Dip
  • 778
  • 5
  • 13
  • 26
  • 1
    why don't use awk? it would be the best for this - http://stackoverflow.com/questions/14022529/how-can-i-change-a-certain-field-of-a-file-into-upper-case-using-awk – m.antkowicz Oct 18 '16 at 08:34

2 Answers2

4

You can use tr to transform from lowercase to uppercase. cut will extract the single columns and paste will combine the separated columns again.

Assumption: Columns are delimited by tabs.

paste <(cut -f1 file) <(cut -f2 file | tr '[:lower:]' '[:upper:]')

Replace file with your file name (that is test in your case).

Socowi
  • 25,550
  • 3
  • 32
  • 54
  • Perfect! I was looking for an answer to not change the delimiter in output. This works fine! – AMS Sep 01 '23 at 22:58
2

In pure bash

#!/bin/bash

while read -r col1 col2;
do
    printf "%s%7s\n" "$col1" "${col2^^}"

done < file > output-file

Input-file

$ cat file
1    abc
2    xyz
3    pqr

Output-file

$ cat output-file
1    ABC
2    XYZ
3    PQR
Inian
  • 80,270
  • 14
  • 142
  • 161