1834932 Members
2691 Online
110071 Solutions
New Discussion

awk query

 
SOLVED
Go to solution
Declan Heerey
Frequent Advisor

awk query

I'm trying to print the 2nd last word of a slash delimited string which is not always the same length

i.e.

http://vss:8080/svn/parallel/Product/one/that file.sql

or

http://vss:8080/svn/parallel/Product/section/one/that file.sql


In this case I always want the "one" to be printed

I have tried several different combos of awk but can only get it to work if i know how many fields are in the string :o(

Any help appreciated
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: awk query

Hi:

# awk -F/ '{print $(NF-1)}'

...as for example:

# X="http://vss:8080/svn/parallel/Product/one/that file.sql"

# echo ${X}|awk -F/ '{print $(NF-1)}'

Regards!

...JRF...
Declan Heerey
Frequent Advisor

Re: awk query

Thanks James

That's done the trick

Cheers
Dennis Handly
Acclaimed Contributor

Re: awk query

You of course can use:
$ echo $(basename $(dirname $XXX))

Where $XXX is the first string.