Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

To cut a string based on last index of identifier

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-25-2013
vivek d r's Unix or Linux Image
vivek d r vivek d r is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 8 April 2015, 10:02 AM EDT
Location: Bangalore, INDIA
Posts: 285
Thanks: 126
Thanked 4 Times in 4 Posts
To cut a string based on last index of identifier

here below is sample string


Code:
null pointer dereference of 'resourceList' where null is returned from a method/opt/bld/fetch/ds/interzone/notification/LocalLineStatusNotificationListener.java:79
null pointer dereference of 'reList' where null is returned from a method/opt/bld/fetch/dunkindev6jbe4/src/com/ip/interzone/notification/LineStatusListener.java:45

i want to cut based on last index of '/' identifier.

i tried


Code:
 
cat fileName.txt | awk '.java' '{print $1}' | cut -d'/' f5

but that would return only for partial since there are different number of '/' for each line.. so i need something to find last index of '/' and cut it and provide me only java file name
Sponsored Links
    #2  
Old Unix and Linux 01-25-2013
Subbeh Subbeh is offline
Registered User
 
Join Date: May 2011
Last Activity: 7 May 2015, 3:00 AM EDT
Posts: 332
Thanks: 37
Thanked 87 Times in 86 Posts
This will get you the filename:


Code:
sed -e 's#.*/##' -e 's/:.*//' inputfile

Or simply use grep:

Code:
grep -o [^/]*java inputfile


Last edited by Subbeh; 01-25-2013 at 05:53 AM..
Sponsored Links
    #3  
Old Unix and Linux 01-25-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 22 May 2015, 12:00 PM EDT
Location: Amsterdam
Posts: 10,201
Thanks: 332
Thanked 2,692 Times in 2,408 Posts

Code:
awk -F'[/:]' '{print $(NF-1)}' file

    #4  
Old Unix and Linux 01-25-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 May 2015, 10:54 AM EDT
Location: Galactic Empire
Posts: 3,402
Thanks: 240
Thanked 1,216 Times in 1,142 Posts

Code:
awk '{gsub(/.*\/|:.*/,"")}1' file

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to cut based on a string gvc UNIX for Dummies Questions & Answers 3 09-06-2012 04:54 AM
build array name based on loop index janavan Shell Programming and Scripting 3 09-03-2012 07:33 AM
awk cut column based on string Shirishlnx Emergency UNIX and Linux Support 15 02-15-2012 04:33 AM
error while extracting a line from a file based on identifier vivek d r Shell Programming and Scripting 4 12-06-2011 04:07 AM
merging column from two files based on identifier phil_heath Shell Programming and Scripting 4 06-12-2009 12:55 AM



All times are GMT -4. The time now is 10:43 PM.