To cut end string from line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To cut end string from line
# 1  
Old 12-19-2007
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  
Old 12-19-2007
Java

Code:
# basename /users/home/test.txt
test.txt
# dirname /users/home/test.txt
/users/home

# 3  
Old 12-19-2007
Code:
# s="/users/home/test.txt"
# echo ${s##*/}
test.txt

# 4  
Old 12-19-2007
Quote:
Originally Posted by ghostdog74
# echo ${s##*/}
Not bourne safe Smilie

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  
Old 12-19-2007
Quote:
Originally Posted by Smiling Dragon
Not bourne safe Smilie
thanks.just curious, do you still use the bourne shell today?
# 6  
Old 12-20-2007
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  
Old 12-20-2007
Quote:
Originally Posted by ghostdog74
thanks.just curious, do you still use the bourne shell today?
Of course! Smilie
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Red Hat

How to add a new string at the end of line by searching a string on the same line?

Hi, I have a file which is an extract of jil codes of all autosys jobs in our server. Sample jil code: ************************** permission:gx,wx date_conditions:yes days_of_week:all start_times:"05:00" condition: notrunning(appDev#box#ProductLoad)... (1 Reply)
Discussion started by: raghavendra
1 Replies

3. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

4. Shell Programming and Scripting

Help Needed! - Cut characters after a text string and append to end of filename

Hi all.. I have several unique files that contain one thing in common, and that is acct#. For all files in the directory, I want to append the 10 characters following the word "ACCOUNT:" to the end of the filename. for example: I have file 111_123 that contains ACCOUNT:ABC1234567 The file... (5 Replies)
Discussion started by: cinderella1
5 Replies

5. Shell Programming and Scripting

Cut line up to a string

hi all In my bash script I want to cut a line up to a specific string and keep the rest of it but only up to a ".How can I do that?I imagine something with sed.. Let's say my line is: Jennifer Jones (student) "id:376765748587/7465674775" NewYork and i only want to keep: ... (9 Replies)
Discussion started by: vlm
9 Replies

6. Shell Programming and Scripting

Cut line from file till the end

Hi I have a 57 line text file and I want to cut first 6 line assigned it to a veriable and again cut next 6 line assigned to same variable till the time file have left 0 line. Please let me know how I can do in scripting. Thanks Sanjay (6 Replies)
Discussion started by: Sanjay2121
6 Replies

7. Shell Programming and Scripting

cut a string in a textfile line per line

i need to cut the string in a textfile but each line has a specific way of cutting it (different lengths) i have a for loop that gets the string line per line, then each line has to be compared: for x in `cat tmp2.txt`; do if; then echo 'BAC' elif ... (6 Replies)
Discussion started by: izuma
6 Replies

8. Shell Programming and Scripting

cut from a particular character to the end of the string

Hi All, I have a string like "9633C01302_2". I need to extract the number(02) after "13" and before "_" and the number coming after "13" and before "_" is not constant, it keeps on changing... Can some one plz help me wth the command.. i tried this echo "9633C01302_2" | cut -d'_' -f1 ..But... (2 Replies)
Discussion started by: grajesh_955
2 Replies

9. Shell Programming and Scripting

How to Select or cut from the certain filed to the end of the line

Hi: I have few rows in file..Like suppose... 9063C0 44 00051363603253033253347 3333 070248 06 9063C0 5G PAN00013 9063C0 44 00061030305040404250724 0506 100248 08 9063C0 43 01 00000089 I need to cut the row starting after... (5 Replies)
Discussion started by: grajesh_955
5 Replies

10. AIX

CUT command - cutting characters from end of string

Hello, I need to delete the final few characters from a parameter leaving just the first few. However, the characters which need to remain will not always be a string of the same length. For instance, the parameter will be passed as BN_HSBC_NTRS/hub_mth_ifce.sf. I only need the bit before the... (2 Replies)
Discussion started by: JWilliams
2 Replies
Login or Register to Ask a Question