how to cut a string from a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to cut a string from a string
# 1  
Old 01-02-2012
how to cut a string from a string

now I have a string

.a/b/c/done

I want to get "done" from it. That is the result should be "done"

sorry for my language before.

Thanks in advance

Last edited by Henryyy; 01-02-2012 at 12:50 PM..
# 2  
Old 01-02-2012
Hi Henryyy,

One way:
Code:
$ str=".a/b/c/done"
$ echo "${str%/*}"
.a/b/c

Regards,
Birei
# 3  
Old 01-02-2012
Sorry for my language, I correct the question.
But thank you all the same
# 4  
Old 01-02-2012
Then, try:
Code:
$ str=".a/b/c/done"
$ echo "${str##*/}"
done

Regards,
Birei
This User Gave Thanks to birei For This Post:
# 5  
Old 01-02-2012
If you're working with directories and want to strip the filename, try this:
Code:
$ basename .a/b/c/done
done

# 6  
Old 01-02-2012
Code:
echo ".a/b/c/done | "awk -F"/" '{print $NF}'

or
Code:
echo ".a/b/c/done |  sed 's|.*/\(.*\)|\1|g'


Last edited by Franklin52; 01-03-2012 at 03:27 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut the string

---------- Post updated at 10:31 AM ---------- Previous update was at 10:28 AM ---------- Hello, I am trying to get the string cut based on the following needs: String1=Submitted request 25574824 for CONCURRENT SQLAP RUAPACTUALSEXT Y RUAPACTUALS122313100616.dat "2013/01/12 14:50:44"... (6 Replies)
Discussion started by: cartrider
6 Replies

2. Shell Programming and Scripting

Cut a string for last 8 characters

Hello All I have a file like this abc.tpt.ctl bdc.tpt.ctl cdw.tpt.ctl I have looped every line using the for Loop, now I want to take each line and cut the .tpt.ctl part of it and store it in a variable and use the variable in same loop. The part I am stuck at is how do I cut the last... (9 Replies)
Discussion started by: nnani
9 Replies

3. Shell Programming and Scripting

Cut the string

Hi in a directory i've files having the following name for_category_info_19990101984301 for_catgry_meta_19991111214601 ------- I just want the name till year and month i.e; for_category_info_199901 for_catgry_meta_199911 How can i achieve the above string Thanks (2 Replies)
Discussion started by: smile689
2 Replies

4. 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

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

Scripting help- cut the string

Hi I am having a file with the following content(its created by ls of a directory): -rw-r----- 1 321 321 0 Oct 14 10:41 xcv23456 -rw-r----- 1 321 321 0 Oct 14 10:41 xcv23457 -rw-r----- 1 321 321 0 Oct 14 10:41 xcv23458 -rw-r----- 1 321 321 ... (6 Replies)
Discussion started by: digitalage
6 Replies

7. Shell Programming and Scripting

How do I cut a string within a string

Hi Here is my requirement: I am reading a string, once its done, need to send into different args. For eg: echo "Enter reason for " read myreason ????? ????? echo STR1, STR2, STR3, STR4 Output: myreason: build_XXX.XX.XX_stop_intranet STR1=build STR2=XXX.XX.XX STR3=stop... (3 Replies)
Discussion started by: amiri2000
3 Replies

8. UNIX for Dummies Questions & Answers

how to use cut to get the last field of a string?

If I am not sure of how many fields a string has, say STR=/homt/root/dir1/dir2/../dirn how to use "cut -d/ -f" to get dirn ? (3 Replies)
Discussion started by: meili100
3 Replies

9. Shell Programming and Scripting

cut First charecter in any string

I wannt to cut first char of any string. str=A2465443 out put will be. str1=A str2=2465443. I tried str2=${?%srt} str1=${str#$str2} it is not working. (6 Replies)
Discussion started by: rinku
6 Replies

10. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies
Login or Register to Ask a Question