0

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

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

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.

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.