- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk help required.
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
Forums
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
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
06-15-2010 03:30 AM
06-15-2010 03:30 AM
ps -ef | grep 4444
weblogic 24185 1 0 Feb 21 ? 0:00 /bin/sh ./startNodeManager.sh rodyserver 4444
From above command I want to capture last three coulmns of the output.
using awk `{print $NF}` I can capture only last column. But I need last three columns. Please help ?
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 03:35 AM
06-15-2010 03:35 AM
Re: awk help required.
ps -ef|grep 4444|grep -v grep | awk '{print $10, $11, $12}'
rgs,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 03:43 AM
06-15-2010 03:43 AM
Solution# X="weblogic 24185 1 0 Feb 21 ? 0:00 /bin/sh ./startNodeManager.sh rodyserver 4444"
# echo ${X}|awk '/ 4444$/ {print $(NF-2),$(NF-1),$NF}'
./startNodeManager.sh rodyserver 4444
This also eliminates the 'grep' since 'awk' does the matching too --- here specifically anchored to the end of the line.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 04:36 AM
06-15-2010 04:36 AM
Re: awk help required.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 05:00 AM
06-15-2010 05:00 AM
Re: awk help required.
> Raj: I'm sorry, but you have to be kidding. The OP wants to capture the last three columns of the output. What's so hard about that?
Pipelines where 'grep', 'sed' and 'awk' are mixed together are red-flags for code that begs to be re-worked. All three filters can perform matching operations. Why spawn multiple processes when one will suffice? Why read and write the same data down the pipeline spawning new processes as you go?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 05:12 AM
06-15-2010 05:12 AM
Re: awk help required.
thanks, seems to be kidding but I am not,
This is a simple statement but looks complex :) as there is no rev command in hp-ux, else it would have been looked simple: (sed simulating the rev here).
$ ps -ef|grep 4444|rev| awk '{print $3,$2,$1}'|rev
Btw, question to Archana,
what is the problem getting 10th/11th & 12th field with awk. ? (Those are last three field).
Also Archana would you mind assigning point at the end? This is not only me, many people has advised the same in many of your thread.!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 05:32 AM
06-15-2010 05:32 AM
Re: awk help required.
> Raj: as there is no rev command in hp-ux, else it would have been looked simple: (sed simulating the rev here).
Yes, and you have to do it *twice* to put the data back into its original order, adding another process and more I/O.
While Linux has 'rev', Perl has 'reverse()':
# X="weblogic 24185 1 0 Feb 21 ? 0:00 /bin/sh ./startNodeManager.sh rodyserver 4444"
# echo $X|perl -nle 'print scalar reverse $_'
4444 revresydor hs.reganaMedoNtrats/. hs/nib/ 00:0 ? 12 beF 0 1 58142 cigolbew
# echo $X|perl -nle '@a=split;print join " ",reverse @a'
4444 rodyserver ./startNodeManager.sh /bin/sh 0:00 ? 21 Feb 0 1 24185 weblogic
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 07:03 AM
06-15-2010 07:03 AM
Re: awk help required.
(0 pts. for this pls)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 10:56 PM
06-15-2010 10:56 PM
Re: awk help required.
The log file contains :-
Red
Yellow
Green
Pls help out ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 11:44 PM
06-15-2010 11:44 PM
Re: awk help required.
You didn't yet assign the points to those who helped you on time, and answered with their valuable times here.
I hope you review the threads after posting, Don't you.?
Your Profile says:
" I have assigned points to 17 of 114 responses to my questions. "
- That means you have not appreciated by assigning points to (114-17) = 97 responses and seems you just dis-respected those answers. Does that make sense!.
- Again it is advised to read the Forum rules and courtesy pages before you start posting.
How do I assign points? :
http://forums11.itrc.hp.com/service/forums/helptips.do?#33
How many points should I assign to replies?
http://forums11.itrc.hp.com/service/forums/helptips.do?#34
Finally:
Here is how you can assign points to all your thread you have ignored so far:
http://forums13.itrc.hp.com/service/forums/pageList.do?forumId=1&&listType=unassigned&userId=WW286726
The Forums community appreciates your efforts to fairly rate the answers you have received.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2010 09:35 AM
06-16-2010 09:35 AM
Re: awk help required.
> Now Iam looking for an statement that Incase particular entry (red...) doesn't exists in dynamic log file then write into other log file.
I presume that you want the list of filenames in which the token doesn't appear. One simple way is:
# grep -v red * /dev/null|awk -F: '{print $1}'|sort -u > myresults
...which looks at all files in your current directory that do *not* contain the token "red". Lines in each file that fail to match are output with the filename and a colon (":") separator before the line content. We snip out this name and reduce the population to a unique list.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2010 03:39 AM
06-17-2010 03:39 AM
Re: awk help required.
# grep -v red * /dev/null | awk -F: '{print $1}' | sort -u
This isn't going to do that. It's going to list all files that have lines that don't have red.
You need something like:
for file in *; do
grep -q -w red $file
if [ $? -ne 0 ]; then
echo "$file" # no scummy red, nowhere
fi
done > ../myresults
>fail to match are output with the filename and a colon
-l already does that.
If you don't want to invoke grep in a loop, you can use vector methods and do grep -l all all files then use comm(3) with ls(1) to weed out the the reds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2010 02:05 PM
06-17-2010 02:05 PM
Re: awk help required.
> Dennis: >JRF: I presume that you want the list of filenames in which the token doesn't appear...This isn't going to do that.
Yes, you are correct of course. I'm not sure what I was thinking and my quick test was a shambles of rigor :-)
A one-liner might be"
# grep -c -w red *|awk -F: '$2==0 {print $1}'
...which would show the filenames *not* containing the "word" 'red'.
Regards!
...JRF...