Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AIX TR TRANSLATE 1

Status
Not open for further replies.

webluca

Programmer
Jan 17, 2008
1
IT
I need to delete the portion of a string after the "."For example:

test_file1.txt

must be translated into

test_file2

I have tried using "tr" command but it deletes every occurences of the string:

echo test_file1.txt | tr -d '.txt'

gives

es_file1

becouse it deletes all ".", all "t", all "x" and all "t"

Thanks for help.
 
That's exactly what tr - translate is supposed to do: translate (or in this case, -d = delete) all occurences of specified characters.

You can use basename to strip off a file extension

[tt]basename $name .txt
name=$(basename $name .txt)[/tt]

Another way is to use parameter substitution:
[tt]name=${name%.txt}[/tt]


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top