以下脚本打印输出:
/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 yarn-env
脚本的输出:
"yarn_log_dir_prefix" : "/var/log/hadoop-yarn",
"yarn_pid_dir_prefix" : "/var/run/hadoop-yarn",
"yarn_user" : "yarn",
"yarn_user_nofile_limit" : "32768",
"yarn_user_nproc_limit" : "65536"
我想添加管道 awk 或 perl oneline 线性,纱线环境在输出的第一个字段中如下:(预期结果)
/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 yarn-env | awk ...
yarn-env "yarn_log_dir_prefix" : "/var/log/hadoop-yarn",
yarn-env "yarn_pid_dir_prefix" : "/var/run/hadoop-yarn",
yarn-env "yarn_user" : "yarn",
yarn-env "yarn_user_nofile_limit" : "32768",
yarn-env "yarn_user_nproc_limit" : "65536"
答案1
/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 yarn-env |
awk '{ print "yarn-env", $0 }'
这个简短的awk
脚本会将字符串添加yarn-env
到命令的每一行输入之前。使用的分隔符是awk
变量OFS
(“输出字段分隔符”,默认情况下为单个空格),因此如果您想在两者之间使用制表符,请使用
/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 yarn-env |
awk -vOFS="\t" '{ print "yarn-env", $0 }'
或者,使用sed
:
/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 yarn-env |
sed 's/^/yarn-env /'
答案2
这是使用 perl 的一种方法:
perl -pe 's/^/yarn_env /'
如您所知,TIMTOWTDI。