在unix中将文件的特定列转换为大写(不使用awk和sed)
我的档案如下 文件名=测试在unix中将文件的特定列转换为大写(不使用awk和sed),unix,Unix,我的档案如下 文件名=测试 1 abc 2 xyz 3 pqr 如何在不使用awk或sed的情况下转换文件的第二列(大写) 在纯bash中 #!/bin/bash while read -r col1 col2; do printf "%s%7s\n" "$col1" "${col2^^}" done < file > output-file 输出文件 $ cat output-file 1 ABC 2 XYZ 3 PQR 在纯b
1 abc
2 xyz
3 pqr
如何在不使用awk或sed的情况下转换文件的第二列(大写) 在纯
bash中
#!/bin/bash
while read -r col1 col2;
do
printf "%s%7s\n" "$col1" "${col2^^}"
done < file > output-file
输出文件
$ cat output-file
1 ABC
2 XYZ
3 PQR
在纯bash中
#!/bin/bash
while read -r col1 col2;
do
printf "%s%7s\n" "$col1" "${col2^^}"
done < file > output-file
输出文件
$ cat output-file
1 ABC
2 XYZ
3 PQR
您可以使用tr
将小写转换为大写cut
将提取单个列,而paste
将再次合并分离的列
假设:列由制表符分隔
paste <(cut -f1 file) <(cut -f2 file | tr '[:lower:]' '[:upper:]')
paste您可以使用tr
将小写转换为大写cut
将提取单个列,而paste
将再次合并分离的列
假设:列由制表符分隔
paste <(cut -f1 file) <(cut -f2 file | tr '[:lower:]' '[:upper:]')
粘贴为什么不使用awk?这将是最好的-为什么不使用awk?这样最好-