Awk匹配TSV列,并用bash中的前缀替换所有行 [英] Awk Match a TSV column and replace all rows with a prefix in bash

查看:147
本文介绍了Awk匹配TSV列,并用bash中的前缀替换所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的TSV文件:

I have a TSV file with the following format:

HAPPY    today I feel good
SAD    this is a bad day
UPSET     Hey please leave me alone!

我必须用__label__之类的前缀替换第一列的值加上我要降低的值,以便将其作为输出

I have to replace the first column value with a prefix like __label__ plus my value to lower, so that to have as output

__label__happy     today I feel good
__label__sad     this is a bad day
__label__upset     Hey please leave me alone!

在外壳中(使用awksed)等

推荐答案

awk 'BEGIN{FS=OFS="\t"}{ $1 = "__label__" tolower($1) }1' infile

这篇关于Awk匹配TSV列,并用bash中的前缀替换所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆