- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sed filtering
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 03:18 AM
09-20-2015 03:18 AM
sed keyword
HI
I need the below output
ps -ef | grep ctm
cimsrvr-ctm 4575 4574 0 Oct 30 ? 473:33 cimservermain --executor-socket 4
Above ps output is an example.
I need to filter the ctm keyword alone.
details=`ps -ef | grep ctm | awk '{print $1}'
echo $details
cimsrvr-ctm
From the above output I need to filter only ctm and I don't want cimsrvr.
I am trying to use sed to filter the keyword but I am not able to find the correct sysntax to sed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 05:54 AM
09-20-2015 05:54 AM
Re: sed keyword
You don't really need "awk". For example:
mba$ echo "cimsrvr-ctm 4575 4574 0 Oct 30 ? 473:33 cimservermain\
--executor-socket 4" | sed -e 's/[^-]*-\([^ ]*\).*/\1/'
ctm
This "sed" command looks for any number of non-hyphens followed by a
hyphen ("[^-]*-"), any number of non-spaces ("[^ ]*"), and any number of
any characters (".*"). For all that, it substitutes ("s/x/y/") the
non-spaces ("\1", the stuff between "\(" and "\)").
> I need to filter the ctm keyword alone.
That could mean many things. I removed the stuff up to the first
hyphen from the first space-separated token. If you want to use "awk"
to separate the first token, then "sed" can remove everything up through
the first hyphen:
mba$ echo 'cimsrvr-ctm' | sed -e 's/[^-]*-//'
ctm
This "sed" command looks for any number of non-hyphens followed by a
hyphen ("[^-]*-"), and substitutes nothing for them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 08:20 AM
09-20-2015 08:20 AM
Re: sed keyword
Thanks for the information.
But I need to get the output only as ctm in first column instead of cimsrvr-ctm when i run ps -ef | grep ctm so that is the reason I have put awk to it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 10:12 AM
09-20-2015 10:12 AM
Re: sed keyword
> [...] so that is the reason I have put awk to it.
Did you look at my first example? Did it work? Did it use "awk"?
You can use "awk" if you wish, but I claim that it's not needed here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 02:24 PM - edited 09-21-2015 01:08 AM
09-20-2015 02:24 PM - edited 09-21-2015 01:08 AM
Re: awk filtering
>I need to get the output only as ctm in first column instead of cimsrvr-ctm when I run ps -ef | grep ctm so that is the reason I have put awk to it.
Please explain EXACTLY what you want and not how you think it should be done. Do you want the user that has embedded "ctm" or the user exactly "ctm"?
Do you want the rest of the ps(1) output? ps(1) has its own filtering options.
> You don't really need "awk".
And alternate statement is that you don't need sed nor grep if you have awk. :-)
If you want the list of all users that have "ctm" as the last 3 chars of the name, running processes:
UNIX95=EXTENDED_PS ps -e -ouser= | awk '/ctm/ {l = length($1); print subst($1, l-3)}' | sort -u
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 09:39 PM
09-20-2015 09:39 PM
Re: sed filtering
I am trying to write a script to start a process if that process is stopped automatically.
Here is my firrst level script.
#!/bin/ksh
#
#
#
pdweb status |grep -w no > /dev/null 2>&1
if [ $? -eq 0 ];then
FailedComponents=`pdweb status |grep -w no |awk '{print $1}'`
for i in $FailedComponents; do
/etc/rc.d/init.d/ahpdweb_start.sh start $i
done
else
echo "All components are up"
fi
-----------------------------
When I run the FailedComponents=`pdweb status |grep -w no |awk '{print $1}'` , I am getting the below ouptiut.
webseald-plaza_portal yes no
webseald-webseald yes yes
webseald-webseald1 yes yes
webseald-webseald2 yes yes
but to start the web seal process I need to input only plaza_portal and not webseald-plaza to /etc/rc.d/init.d/ahpdweb_start.sh start $i
So I am trying to ignore all the keyword before "-"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 09:56 PM
09-20-2015 09:56 PM
Re: sed filtering
> So I am trying to ignore all the keyword before "-"
Ok. Again, did you look at my "sed" examples? Did they work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2015 01:06 AM
09-21-2015 01:06 AM
Re: awk filtering
>Here is my first level script.
Assuming the length of the prefix is always 9:
FailedComponents=$(pdweb status | awk '$2 == "no" || $3 == "no" {print substr($1, 10)}')
if [ "$FailedComponents" != "" ]; then
for i in $FailedComponents; do
/etc/rc.d/init.d/ahpdweb_start.sh start $i
done
else
echo "All components are up"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2015 09:54 PM - edited 10-30-2015 10:29 PM
10-30-2015 09:54 PM - edited 10-30-2015 10:29 PM
Re: sed keyword
> You don't really need "awk".
An alternate statement is that you don't need sed nor grep if you have awk. :-)
(some how I never posted this back in Sep 20, found it my autosave drafts.)