The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
make multiple line containing a pattern into single line VTAWKVT Shell Programming and Scripting 13 12-04-2008 06:40 PM
Grepping 1 line above and below pattern iAm4Free Shell Programming and Scripting 4 10-07-2007 10:24 PM
add a line after a pattern melanie_pfefer Shell Programming and Scripting 2 05-07-2007 01:38 PM
sed - Replace Line which contains the Pattern match with a new line kousikan Shell Programming and Scripting 2 03-24-2007 07:24 AM
Replacing more than 1 pattern in a line Manan Shell Programming and Scripting 6 12-28-2006 01:58 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-21-2007
FK_Daemon FK_Daemon is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 2
Printing out pattern in line

I've scoured the forum and found similar problems but I can't seem to adapt them to help me with my cause.

This is a two-part question.

I have a multi line file generated by ps | -ef

I need to print out a certain type of pattern. The pattern is part static and part dynamic.

It is a file/s(pattern) that contain/s two letters and three to four numbers and sometimes even letter at the end.

e.g GY1020.def, WN093.def and so on. The files(patterns) are located in different directories (some with very long names) so the result from "ps -ef" cuts off part of the extension (.def) so it reads WN093.d

The output from "ps -ef" looks something like this (last two columns shown below):

/bin/ksh /export/home/user/RUN/DEFFILES/GY/GY1020.def G
/bin/ksh /export/home/user/RUN/DEFFILES/WN/RST/WN093.d
/bin/ksh /export/home/user/VB9530.def /more/text/ 1
/bin/ksh /export/home/user/RUN/DEFFILES/LO/LO6002a.def

I want to print out:
GY1020
WN093
VB9530
LO6002a

alternatively: (appending .def for those that get cut off)
GY1020.def
WN093.def
VB9530.def
LO6002a.def

I know "sed" can do this and search for [A-Z][A-Z][0-9][0-9][0-9] or something similar but I cannot get exactly what I want.

The second part of my question; Is there a way to get "ps" to output ALL data and not just cut the end of as shown above?

Some help with this would be very much appreciated.

Last edited by FK_Daemon; 11-21-2007 at 10:57 AM..
  #2 (permalink)  
Old 11-21-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
if on Solaris try: '/usr/ucb/ps -awww'
Code:
/usr/ucb/ps -awww | nawk '$2 ~ /[.]def$/ {n=split($2, a, "(/|[.])"); print a[n-1]}'

Last edited by vgersh99; 11-21-2007 at 11:10 AM..
  #3 (permalink)  
Old 11-21-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
With sed:

Code:
ps -f | sed 's!.*\/\(.*\)\..*!\1!'
with the extension ".def":

Code:
ps -f | sed 's!.*\/\(.*\)\..*!\1.def!'
Regards

Last edited by Franklin52; 11-21-2007 at 12:40 PM..
  #4 (permalink)  
Old 11-23-2007
FK_Daemon FK_Daemon is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 2
Thanks for the replies. They helped me a lot.

I thought about matching everything between "/" and "." too, but I was a bit worried that even the "." might get cut off (not to mention that I am no ace when it comes to sed). Hopefully that won't occur. I will look more closely at ps -awww in the future as I run all my scripts on Solaris.

Thanks once again, you guys are awesome.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0