To cut a string based on last index of identifier | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

To cut a string based on last index of identifier

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-25-2013
vivek d r's Avatar
vivek d r vivek d r is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 16 July 2014, 11:32 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 01-25-2013
Subbeh Subbeh is offline
Registered User
 
Join Date: May 2011
Last Activity: 25 September 2014, 10:40 AM EDT
Posts: 328
Thanks: 35
Thanked 86 Times in 85 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 01-25-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 30 September 2014, 1:26 AM EDT
Location: Amsterdam
Posts: 9,487
Thanks: 280
Thanked 2,398 Times in 2,150 Posts

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

    #4  
Old 01-25-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 26 September 2014, 6:37 PM EDT
Location: Galactic Empire
Posts: 3,385
Thanks: 234
Thanked 1,208 Times in 1,134 Posts

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

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:56 AM.