1

How to print from the field separator ":" until end of the line

example:

echo " llap_java_opts  :  -XX:+AlwaysPreTouch {% if java_version > 7 %}-XX:+UseG1GC -XX:TLABSize=8m -XX:+ResizeTLAB -XX:+UseNUMA -XX:+AggressiveOpts"

llap_java_opts  :  -XX:+AlwaysPreTouch {% if java_version > 7 %}-XX:+UseG1GC -XX:TLABSize=8m -XX:+ResizeTLAB -XX:+UseNUMA -XX:+AggressiveOpts

expected output:

-XX:+AlwaysPreTouch {% if java_version > 7 %}-XX:+UseG1GC -XX:TLABSize=8m -XX:+ResizeTLAB -XX:+UseNUMA -XX:+AggressiveOpts

3 Answers 3

3

I would use cut -d: -f2- for this:

echo " llap_java_opts  :  -XX:+AlwaysPreTouch {% if java_version > 7 %}-XX:+UseG1GC -XX:TLABSize=8m -XX:+ResizeTLAB -XX:+UseNUMA -XX:+AggressiveOpts" | cut -d: -f2-
3

Pass it through

sed 's/^[^:]*: *//'

This sed substitution will delete everything from the beginning of the line up to and including the first : and any spaces after it.

If you have the string in a shell variable $a then

printf -- '-%s\n' "${a#*-}"

This uses the parameter expansion ${parameter#word} to delete everything up to and including the first -. The dash is inserted again by the printf. This does not use any external utilities when run in most modern shells.

0

Using grep:

grep -Po ':\K.*' infile

the \K assertion will ignore to printing everything before and first colon : seen.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.