The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacing a string in nth line maxmave Shell Programming and Scripting 1 06-04-2008 05:32 PM
regexp to get first line of string jonas.gabriel Shell Programming and Scripting 3 05-09-2007 03:46 AM
get the NF of a string line ozzman Shell Programming and Scripting 5 02-02-2007 01:01 AM
How I Can get String From the Line habuzahra UNIX for Dummies Questions & Answers 2 10-29-2006 07:55 AM
Add string after line X alienET Shell Programming and Scripting 2 10-13-2005 09:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-19-2007
visu visu is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 3
To cut end string from line

HI,

I want to cut end string from line.

e.g. i have following input line

/users/home/test.txt

I want to get end string 'test.txt' from above line and length of that end string will change and it always start after '/'.

Thanks,

Visu
  #2 (permalink)  
Old 12-19-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Post

Code:
# basename /users/home/test.txt
test.txt
# dirname /users/home/test.txt
/users/home
  #3 (permalink)  
Old 12-19-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
Code:
# s="/users/home/test.txt"
# echo ${s##*/}
test.txt
  #4 (permalink)  
Old 12-19-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Quote:
Originally Posted by ghostdog74 View Post
# echo ${s##*/}
Not bourne safe

Last edited by Smiling Dragon; 12-19-2007 at 10:42 PM.. Reason: Added emote - don't want it to sound like something it's not
  #5 (permalink)  
Old 12-19-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
Quote:
Originally Posted by Smiling Dragon View Post
Not bourne safe
thanks.just curious, do you still use the bourne shell today?
  #6 (permalink)  
Old 12-20-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
awk

Hi,

input:
Code:
/users/home/test.txt
/users/home/bin/test_test.txt
/users/local/home/testaa.txt
output:
Code:
test.txt
test_test.txt
testaa.txt
code:
Code:
awk 'BEGIN{FS="/"}
{
print $NF
}' filename
  #7 (permalink)  
Old 12-20-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Quote:
Originally Posted by ghostdog74 View Post
thanks.just curious, do you still use the bourne shell today?
Of course!
if you're writing shell scripts for system stuff or if you are working as root, bourne is the only safe shell to use IMO.
For simple userland stuff I'll use bash, but even then I still script in sh - the extra features of ksh are nice but I only use ksh script when I need them as sh scripts work in everything else.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0