The following script prints the output down:

/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 yarn-env

The output of the script:

 "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"

I want to add with pipeline the awk or perl oneline linear, the yarn-env in the first field of output as the following: (expected results)

/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"
/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 yarn-env |
awk '{ print "yarn-env", $0 }'

This short awk script will prepend the string yarn-env to each line of input from your command. The delimiter used is the awk variable OFS ("output field separator", a single space by default), so if you want a tab between the two, use

/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 yarn-env |
awk -vOFS="\t" '{ print "yarn-env", $0 }'

Alternatively, using sed:

/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 yarn-env |
sed 's/^/yarn-env /'

Here is one way with perl:

perl -pe 's/^/yarn_env /'

As you may know, TIMTOWTDI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.