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: 3 December 2014, 1:47 AM EST
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: 16 December 2014, 8:22 AM EST
Posts: 330
Thanks: 36
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 06: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: 17 December 2014, 2:27 PM EST
Location: Amsterdam
Posts: 9,688
Thanks: 300
Thanked 2,491 Times in 2,230 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: 17 December 2014, 4:49 PM EST
Location: Galactic Empire
Posts: 3,395
Thanks: 240
Thanked 1,211 Times in 1,137 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 05:54 AM
build array name based on loop index janavan Shell Programming and Scripting 3 09-03-2012 08:33 AM
awk cut column based on string Shirishlnx Emergency UNIX and Linux Support 15 02-15-2012 05:33 AM
error while extracting a line from a file based on identifier vivek d r Shell Programming and Scripting 4 12-06-2011 05:07 AM
merging column from two files based on identifier phil_heath Shell Programming and Scripting 4 06-12-2009 01:55 AM



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