Remove last few words from Line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove last few words from Line
# 1  
Old 11-04-2013
Remove last few words from Line

Hi I would like to remove last few words from File

Could anybody Help on it.

ps -ef | grep mgr.prm | awk '{print $10}'
/opt/app/dummyd/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm


I want output like

/opt/app/dummyd/xyz
/opt/app/dummyab/xyz
/opt/app/dummydcdd/xyz

Help Appreciated.
# 2  
Old 11-04-2013
Try:
Code:
ps -ef | grep mgr.prm | awk '{print $10}' | sed 's!/dirprm/mgr\.prm$!!'

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 11-04-2013
Try

Code:
ps -ef | grep mgr.prm | awk -F"/" 'NF-=2' OFS="/"

Sample Output
Code:
$ cat <<eof | awk -F"/" 'NF-=2' OFS="/"
/opt/app/dummyd/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm
eof

/opt/app/dummyd/xyz
/opt/app/dummy/xyz
/opt/app/dummy/xyz

# 4  
Old 11-04-2013
Thanks bartus11 , It really worked.
# 5  
Old 11-04-2013
Quote:
Originally Posted by tapia
Hi I would like to remove last few words from File

Could anybody Help on it.

ps -ef | grep mgr.prm | awk '{print $10}'
/opt/app/dummyd/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm
/opt/app/dummy/xyz/dirprm/mgr.prm


I want output like

/opt/app/dummyd/xyz
/opt/app/dummyab/xyz
/opt/app/dummydcdd/xyz

Help Appreciated.
I don't get it. Where did the characters marked in red above come from?

I can understand wanting to remove the final two components of the selected pathnames, but I don't understand the logic that seems to produce random characters that do not appear in the input. Also, you said you wanted to remove a few words. Pathname components are not usually described as "words". And, is a few always two, or is there something else you haven't told us?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. Shell Programming and Scripting

USING sed to remove multiple strings/words from a line

Hi I use sed comnand to remove occurance of one workd from a line. However I need to removed occurance of dufferent words in ne line. Original-1 Hi this is the END of my begining Comand sed s/"END"/"start"/g Output-1 Hi this is the start of my beginig But I have more... (9 Replies)
Discussion started by: mnassiri
9 Replies

3. Shell Programming and Scripting

remove words

All, I have a file with below entries. /java/usr/abc/123 /java/usr/xyz/123_21 /java/usr/ab12/345/234 ......... ......... And I need entry as /java/usr/abc/config /java/usr/xyz/config /java/usr/ab12/config ......... ......... Actually, I need to remove all other entries... (2 Replies)
Discussion started by: anshu ranjan
2 Replies

4. Shell Programming and Scripting

Remove all words after first space from each line

My file looks like: asd absjdd sdff vczxs wedssx c dasx ccc I need to keep asd sdff wedssx dasx How do I do that experts?:wall::wall: (1 Reply)
Discussion started by: hakermania
1 Replies

5. Shell Programming and Scripting

How to remove all words from a matching word in a line?

Hi Guys, :p I have a file like this: 2010-04-25 00:00:30,095 INFO - ]- start process U100M4 2010-04-25 00:00:30,096 DEBUG - ] -- call EJB 2010-04-25 00:00:30,709 INFO - - end processU100M4 2010-04-25 00:00:30,710 DEBUG - got message=Sorry I want to out put format. 2010-04-25... (5 Replies)
Discussion started by: ooilinlove
5 Replies

6. Shell Programming and Scripting

How to remove all words starting from a matching word in a line

Hi Guys, I have a file like this: wwwe 1 ioie ewew yyy uuu 88 erehrlk 4 ihoiwhe lkjhassad lkhsad yyy mmm 45 jhash lhasdhs lkhsdkjsn ouiyrshroi oihoihswodnw oiyhewe yyy ggg 77 I want to remove everything after "yyy" and including "yyy" from each line in the file. So I want:... (2 Replies)
Discussion started by: npatwardhan
2 Replies

7. Shell Programming and Scripting

Need to remove the words

Hi folks, I have file with the below 1245633505 +manual mroennfeldt@news.com.au 1245633506 +manual sal@bynews.com.au 1245633506 +manual whson@btimes.com 1245633507 +manual karla.marsden@tnews.com.au 1245633508 +manual king@netn.com.au Now, I need the output of the files only with... (4 Replies)
Discussion started by: gsiva
4 Replies

8. Shell Programming and Scripting

remove duplicate words in a line

Hi, Please help! I have a file having duplicate words in some line and I want to remove the duplicate words. The order of the words in the output file doesn't matter. INPUT_FILE pink_kite red_pen ball pink_kite ball yellow_flower white no white no cloud nine_pen pink cloud pink nine_pen... (6 Replies)
Discussion started by: sam_2921
6 Replies

9. UNIX for Advanced & Expert Users

Remove words from file

Hello, I have a question: I have two different files, let's call them file1 and file2. file1 contains a list of words, the words are on seperate lines: word1 word2 word3 word4 etc... file2 also contains a list of words, seperated in the same way as file1. What I want to do is... (5 Replies)
Discussion started by: Beeser
5 Replies

10. Shell Programming and Scripting

remove first few words from a line

Hi All, Sample: 4051 Oct 4 10:03:36 AM 2008: TEST: end of testcase Checking Interface after reload, result fail I need to remove first 10 words of the above line and output should be like Checking Interface after reload, result fail Please help me in this regard. Thanks, (4 Replies)
Discussion started by: shellscripter
4 Replies
Login or Register to Ask a Question