Results 1 to 6 of 6
Hi iam a new user in this forum and Linux.
I have a string like this "/home/test/filename.txt"
and i want to delete all character after the last "/".
how to ...
- 06-27-2010 #1Just Joined!
- Join Date
- Jun 2010
- Posts
- 8
How to remove the last character.
Hi iam a new user in this forum and Linux.
I have a string like this "/home/test/filename.txt"
and i want to delete all character after the last "/".
how to do that using sed or awk.
sorry my english is bad.
- 06-27-2010 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
welcome to the forum
if your input is called A, then something like this might work:
tr / \\n <A | sed '$d' | tr \\n / >Bthe sun is new every day (heraclitus)
- 06-27-2010 #3Just Joined!
- Join Date
- Jun 2010
- Posts
- 8
Thanks for answer, its work
Can you explain that
- 06-27-2010 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Using built-ins in shell bash allows one to avoid external programs:
producing:Code:#!/usr/bin/env bash # @(#) s1 Demonstrate bash in-built syntax for string manipulation. echo t1="/home/test/filename.txt" echo " Original: $t1" echo echo " Modified: ${t1%/*}/" exit 0
See topic Parameter Expansion in man bash for details ... cheers, drlCode:% ./s1 Original: /home/test/filename.txt Modified: /home/test/
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 06-27-2010 #5
Also, the dirname program does this for files specifically.
- 06-27-2010 #6Just Joined!
- Join Date
- Jun 2010
- Posts
- 8
Thank you very much.
can anyone explain this
tr / \\n <A | sed '$d' | tr \\n / >B


Reply With Quote