LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-26-2017, 05:28 PM   #1
hjo99729
LQ Newbie
 
Registered: Oct 2017
Posts: 1

Rep: Reputation: Disabled
from ps -ef | grep java how can I grep out Xms & Xmx value


I need to get everything in one line

I can get one at a time with
ps -ef | grep -o 'Xms[0-9]*'
ps -ef | grep -o 'Xmx[0-9]*'
and get the cell with
grep java | awk '{print $(NF-2),($NF-1)}'

but I know there has got to a better way

I can awk the Xms and Xmx but depending on how the java server is configured it comes up in a different place
 
Old 10-26-2017, 05:38 PM   #2
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 759

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Welcome to LQ. I incorrectly first thought of the -v switch.
Maybe this will help: https://unix.stackexchange.com/quest...-single-column
Others will likely come along later, with better answers.

Last edited by !!!; 10-26-2017 at 05:46 PM.
 
Old 10-26-2017, 05:50 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,773

Rep: Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571
Quote:
Originally Posted by hjo99729 View Post
I can awk the Xms and Xmx but depending on how the java server is configured it comes up in a different place
Why does that matter ?. awk has more than enough capabilities to do everything you want - it has regex matching on a par with grep, and can save to variables that can be printed in any order you want. No need to rely only on field count.
You should never need to pipe something like grep into awk - do it all in awk.
 
Old 10-26-2017, 07:39 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,873

Rep: Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600
Here's a couple of variations

Code:
ps -ef|grep -v grep|egrep -o 'Xms[0-9]*|Xmx[0-9]*' |tr '\r' ' '
Xms2
Xmx2

ps -ef|grep -v grep|egrep -o 'Xms[0-9]*|Xmx[0-9]*' |tr '\n' ' ' ;echo
Xms2 Xmx2
Just for fun
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find & grep - how to return pathes, not grep phrases ? postcd Linux - General 2 11-25-2014 12:43 PM
grep to file outputs more than grep to screen? tcpman Linux - Server 4 06-07-2013 04:46 AM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration