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
  • 648
  • 4
  • 13
  • 24
  • 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

3

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
  • 22,529
  • 3
  • 25
  • 46
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
  • 71,145
  • 9
  • 121
  • 139