Visit Our UNIX and Linux User Community


How to grep the required part from the string?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grep the required part from the string?
# 1  
Old 08-14-2013
How to grep the required part from the string?

Hi All,

I am trying to fetch the particular content from the result of grep command.

I am using

Code:
 
 
ps-ef |grep engine| awk '{print $6}'

above statement giving me

Code:
 
/opt/test/user/domain/CORPTEST/application/CacheScheduler/CacheScheduler-CacheScheduler

but I want

Code:
 
CacheScheduler-CacheScheduler

the end part of that output. Please suggest your valuable suggestions to get that required output.
# 2  
Old 08-14-2013
Code:
ps -ef | awk '/engine/{sub(/.*\//,x,$6); print $6}'

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 08-14-2013
Thanks ahamed, it works like a charm.

My mistake, dint mention in the first post itself.
Last word is CacheScheduler-CacheScheduler.ear

its is giving me the exact, but wanted to know if there is way to remove the.ear also from the end?

Bunch of thanks again.
# 4  
Old 08-14-2013
Code:
ps -ef | awk '/engine/{gsub(/.*\/|\..+/,x,$6); print $6}'

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 5  
Old 08-14-2013
@sarsour
Can you post the output of (everything it gives):
ps -ef | grep engine
# 6  
Old 08-14-2013
Hi Ahamad,

I was trying to print some of the middle value of the string like

Code:
/opt/test/user/domain/CORPTEST/application/CacheScheduler/CacheScheduler-CacheScheduler

I want CORPTEST as the output,

I was trying using SED,
Code:
sed -e '/domain/,/application/p'|ps -ef | awk '{print $12}'

but it is dipalying the whole string only.
# 7  
Old 08-14-2013
Please post this
ps -ef | grep engine
It will help us to make a complete working script.
At the moment, we do not now where in your output string data is located.
I guess at the end of the line..

Previous Thread | Next Thread
Test Your Knowledge in Computers #112
Difficulty: Easy
macOS was not the largest Unix largest installed base in 2017.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/awk : to grep only required pattern disk

Hi Experts, Need help with the following: Desired output: Only want to get the output marked in green. The file: --- Physical volumes --- PV Name /dev/disk/disk4704 PV Status available Total PE 6399 Free PE ... (3 Replies)
Discussion started by: rveri
3 Replies

2. Shell Programming and Scripting

Grep a part of file based on string identifiers

consider below file contents cat myOutputFIle.txt 8 CCM-HQE-ResourceHealthCheck: Resource List : No RED/UNKNOWN resource Health entries found ---------------------------------------------------------- 9 CCM-TraderLogin-Status: Number of logins: 0... (4 Replies)
Discussion started by: vivek d r
4 Replies

3. AIX

Grepping before and after lines for required string

Hi All, I am new to AIX unix . i need to grep for a pattern and if pattern is found then i need 3 before the pattern line found and 3 lines after the pattern found. (11 Replies)
Discussion started by: coolvibh
11 Replies

4. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

5. Shell Programming and Scripting

grep part of word or Another word from a string

Hi all, FileOne family balance >>>>> 0 0 0 0 java.io.FileNotFoundException: Settings.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) .. .... ..... ..... java.lang.NullPointerException ... ..... ...... Stacktrace: at... (2 Replies)
Discussion started by: linuxadmin
2 Replies

6. Shell Programming and Scripting

searching the required string and appending string to it.

Hi all, I have some data in the form of adc|nvhs|nahssn|njadnk|nkfds in the above data i need to write a script so thet it will append "|||" to the third occurnace in the string ..... the outout should look like adc|nvhs|nahssn||||njadnk|nkfds Thanks, Firestar. (6 Replies)
Discussion started by: firestar
6 Replies

7. Shell Programming and Scripting

Help Required For String Matching

I am new to shell scripting !!!!!!!!!!.ANY HELP WOULD BE APPRECIATE :- i want to write a script that will check the log for string: waiting for seconds for this I am using :- tail -10 log.20101004 | tail -1 and grep the "string" but when matching error is coming ,see script below:- i... (1 Reply)
Discussion started by: abhigrkist
1 Replies

8. Shell Programming and Scripting

grep required data from two columns

hello, I have output from a command and I need to filter some info out of that. I tried awk command but I can not grep what I am looking for: Following is the output and I need to capture "disabled" for each volume from first column and report: # vol status Volume State ... (2 Replies)
Discussion started by: za_7565
2 Replies

9. UNIX for Dummies Questions & Answers

grep required pattern and next 2 or 3 lines

dear ones pl.kindly help me 1) how to print(grep) required pattern and following 2 or 3 lines. 2) grep required pattern(to print)+above 2 lines+below 2 or 3 lines.from a report file. ex: we have some report file kf askfjsk fksaj fk skf sjfksjd kff sjfkjs kf jskdjfklsd jfklsdf sdkfjsd fsd... (3 Replies)
Discussion started by: cvvsnm
3 Replies

10. Shell Programming and Scripting

Help required in grep command

Hi all, I need some help in grep command in a ksh script. Actually, i need to list all files having the file name like "BORD*.DAT" but exclude the files (from the list) having name like "BORD*mgt*.DAT". For that i used the following command: ls | grep "BORD*.DAT" | grep -v "BORD*mgt*.DAT" ... (4 Replies)
Discussion started by: panzer
4 Replies

Featured Tech Videos