I am trying to print out a number next to a string that I search (using shell script).For ex., my file contains a linearg[30] = -Xmx4096mI search the file with string Xmx and I need the output of next digits attached to the string and nothing else is needed in the output. How can I achieve this?
How to grep a string in a file and output the digits next to the string
grep
If your version of grep supports PCRE mode, you can use grep -Po 'Xmx\K\d+'Ex.echo 'F arg[30] = -Xmx4096m' | grep -Po 'Xmx\K\d+'4096