Cut on last backslash on hyperlink string-sed/awk??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut on last backslash on hyperlink string-sed/awk??
# 1  
Old 04-07-2011
Cut on last backslash on hyperlink string-sed/awk??

hyper link- abc:8081/xyz/2.5.6/rtyp-2.5.6.jar

Needs to get "rtyp-2.5.6.jar" i.e character after last backslash "/"
how to do this using sed/awk??

help is highly appreciated.
# 2  
Old 04-07-2011
Code:
echo 'hyper link- abc:8081/xyz/2.5.6/rtyp-2.5.6.jar' | awk -F/ '{print $NF}'

# 3  
Old 04-07-2011
thanks pravin u the master .
this site is excellent .hope i learn well from here.
once again thanks a ton
# 4  
Old 04-07-2011
thanks pravin for quick & perfect reply. you genious.
hope i learn well more from this site.
once again hats off from a unix beginner Smilie

---------- Post updated at 02:42 PM ---------- Previous update was at 02:40 PM ----------

btw: can we do this similar thing using sed?? will help me in directly replacing in the file.
# 5  
Old 04-07-2011
sed
Code:
echo 'hyper link- abc:8081/xyz/2.5.6/rtyp-2.5.6.jar' |sed 's:.*/::g'

OR
Code:
p='hyper link- abc:8081/xyz/2.5.6/rtyp-2.5.6.jar'
echo ${p##*/}

# 6  
Old 04-07-2011
Using split method (Ruby1.9+)
Code:
$ echo "abc:8081/xyz/2.5.6/rtyp-2.5.6.jar" | ruby -e 'puts gets.split("/")[-1]'
rtyp-2.5.6.jar

Using regex
Code:
$ echo "abc:8081/xyz/2.5.6/rtyp-2.5.6.jar" | ruby -e 'puts gets.gsub(/.*\//,"")'
rtyp-2.5.6.jar

# 7  
Old 04-07-2011
wow! ruby also looks good.
one issue facing is i have to do this in a file.
whose content is like
file.txt>>

anb/xrg/zxczxc.java
admin/WEB-INF/struts-config.xml
h-t-t-p://abc:8081/xyz/2.5.6/rtyp-2.5.6.jar

**h-t-t-p stands for hyperlink .not allowed to post them as of now Smilie

i need to cut only "http" lines with the jar names.
here its cutting all the lines & printing the last string after backslash.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace backslash at the end of the string using sed command

I have text file which is a tab delimited one. Sample data from the file is shown below: unix is\ great\ os linux\ is superb I want to replace that backslash with empty string preserving the tab delimiter. Output should be unix is great os linux is ... (3 Replies)
Discussion started by: p.akhilreddy4u
3 Replies

2. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

3. Shell Programming and Scripting

sed cut characters of string

helloo I wonder if there's a way to cut characters out of a string and keep only the last 2 by using sed. For example if there's the todays' date: 2012-05-06 and we only want to keep the last 2 characters which are the day. Is there a quick way to do it with sed? (2 Replies)
Discussion started by: vlm
2 Replies

4. Emergency UNIX and Linux Support

awk cut column based on string

Using awk I required to cut out column contain word "-Tag" regardles of any order of contents and case INsensitive -Tag:messages -P:/var/log/messages -P:/var/log/maillog -K:Error -K:Warning -K:critical Please Guide ...... --Shirish Shukla ---------- Post updated at 05:58 AM... (15 Replies)
Discussion started by: Shirishlnx
15 Replies

5. Shell Programming and Scripting

Substring using cut/awk/sed

Hi Gurus,I have a seemingly simple problem but struggling with it.It is as follows : I/p string - ABCDEFGHIJ20100909.txt desired o/p - AB,DEF,20100909,ABCDEFGHIJ20100909.txt How to achieve it ?Thanks in advance. Please use code tags, thank you (20 Replies)
Discussion started by: sumoka
20 Replies

6. Shell Programming and Scripting

how to cut string with wildcard (sed)

i got text file and contain.... SKYPE Dec 11 09:26:05 IN=eth0 OUT=eth1 SRC=75.38.161.80 DST=192.168.1.56 PROTO=UDP SPT=30645 DPT=12630 LEN=66 SKYPE Dec 11 09:26:05 IN=eth1 OUT=eth0 SRC=192.168.1.56 DST=118.109.39.86 PROTO=UDP SPT=12630 DPT=15889 LEN=75 SKYPE Dec 11 09:26:05 IN=eth1 OUT=eth0... (2 Replies)
Discussion started by: slackman
2 Replies

7. Shell Programming and Scripting

Sed and awk backslash characters

Hi, I have a variable read from user input: PROFILESROOTDIR="\\194.185.82.188\CMSRepository\EncodingProfiles" awk -F"=" -v gr=$PROFILESROOTDIR '/ProfilesRootDirectoryFromXOEMachine/{$2=gr;}1' OFS="=" $CFGFILE > "${CFGFILE}_new" For this awk to work properly I need to replace in the... (7 Replies)
Discussion started by: potro
7 Replies

8. Shell Programming and Scripting

cut in sed/awk

Hi Can i have an example where i should be able to cut columns (like for eg cut -c 1-3) in sed or awk. Regards Dhana (12 Replies)
Discussion started by: dhanamurthy
12 Replies

9. Shell Programming and Scripting

awk,sed or cut problem

Good afternoon, Sir's, I would like to seek your assistance regarding on this matter. $cat file1 111 aaaa bbb aass aaa files file1 temp temp1 pix 222 11 22 1 33 44 desired output: aaaa bbb aass files file1 temp1 222 11 22 1 33 44 thanks (7 Replies)
Discussion started by: invinzin21
7 Replies

10. UNIX for Dummies Questions & Answers

cut vs. sed vs. awk ?

hi again...need new help guys:p the file contains following infos... users/abc/bla1.exe newusers/defgh/ik/albg2.exe users2/opww/ertz/qqwertzu/rwerwew.exe how to get the file content into... users/abc/ newusers/defgh/ik/ users2/opww/ertz/qqwertzu/ with... you can erase the... (5 Replies)
Discussion started by: svennie
5 Replies
Login or Register to Ask a Question