Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-25-2013
vivek d r's Avatar
Registered User
 
Join Date: Nov 2011
Location: Bangalore, INDIA
Posts: 277
Thanks: 124
Thanked 3 Times in 3 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
Registered User
 
Join Date: May 2011
Posts: 143
Thanks: 27
Thanked 22 Times in 22 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
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,384
Thanks: 144
Thanked 1,756 Times in 1,593 Posts

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

    #4  
Old 01-25-2013
Yoda's Avatar
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,321
Thanks: 154
Thanked 742 Times in 714 Posts

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

Sponsored Links
Reply

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 !! Help Me!! 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 09:55 AM.