Wanted to eliminate numeric part from a filename


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Wanted to eliminate numeric part from a filename
# 1  
Old 07-17-2006
Wanted to eliminate numeric part from a filename

Hi,

I have a filename called XYZ12345.txt.I just want to eliminate numeric and have only XYZ.txt.

How can i do it ?

Regards,
Sona.
# 2  
Old 07-17-2006
Multiple ways of doing it.

Here is one.
Code:
echo XYZ12345.txt | tr -d '[[:digit:]]'

With out the character class the tr statement would be
Code:
tr -d '0-9'

# 3  
Old 07-17-2006
Question Special characters

I have similar problem, but instead of numeric, i would like to remove a special character from a file name: i have a lot of log files that have '@' in the name of the file. Is the way to remove that character the same? Thank you in advance.
# 4  
Old 07-17-2006
Quote:
Originally Posted by ghost01
I have similar problem, but instead of numeric, i would like to remove a special character from a file name: i have a lot of log files that have '@' in the name of the file. Is the way to remove that character the same? Thank you in advance.
Change the pattern in tr

Code:
echo "@a@b" | tr -d '@'

# 5  
Old 07-20-2006
Question

Quote:
Originally Posted by vino
Change the pattern in tr

Code:
echo "@a@b" | tr -d '@'

Thank you for the response. But if i want to rename it, i can't use echo.
I want
history_acc@MTB-20060716.log
rename in
history_accMTB-20060716.log

I tried with mv, but it didn't work. The command i tried was:
mv history_acc@MTB-20060716.log history_acc@MTB-20060716.log | tr -d '@'.
Do you have any suggestions about that?
# 6  
Old 07-20-2006
Code:
mv history_acc@MTB-20060716.log `echo history_acc@MTB-20060716.log | tr -d '@'.`


Last edited by reborg; 07-20-2006 at 09:47 AM.. Reason: remove rogue VB tags.
# 7  
Old 07-20-2006
I tried that too. But instead of file named:
history_accMTB-20060716.log
i got file named
echo history_acc@MTB-20060716.log[/email] | tr -d '@'
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename first N numeric strings in filename

Hello, I have some video files containing numbers and characters . To tell the problem shortly, due to a limitation, I am unable create a playlist regularly changing on a daily basis with the command shuffle....So I decided to rename filenames, just a replacement of first five numbers randomly.... (10 Replies)
Discussion started by: baris35
10 Replies

2. Shell Programming and Scripting

To eliminate the created filename

Hi All, I have two files in the directory file1.txt file2.txt I gave ls -m > output.txt command and I got the output as file1.txt, file2.txt, output.txt But my output should be like file1.txt, file2.txt Thanks in advance. (6 Replies)
Discussion started by: dubuku_01
6 Replies

3. Shell Programming and Scripting

Sort log files based on numeric value in the filename

Hi, I have a list of log files as follows: name_date_0001_ID0.log name_date_0001_ID2.log name_date_0001_ID1.log name_date_0002_ID2.log name_date_0004_ID0.log name_date_0005_ID0.log name_date_0021_ID0.log name_date_0025_ID0.log .......................................... (4 Replies)
Discussion started by: alex2005
4 Replies

4. Shell Programming and Scripting

[Solved] sort on numeric part of field

I have ran into a heavy case of PEBCAK*) and could need some advice on what i do wrong: OS is Linux (kernel 2.6.35), sort --version reports "8.5" from 2010, shell is ksh. Originally i had a file with with the following structure: hdisk1 yyy hdisk2 yyy hdisk3 yyy hdisk4 yyy hdisk5 yyy... (2 Replies)
Discussion started by: bakunin
2 Replies

5. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

6. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

7. Shell Programming and Scripting

Getting part of a filename

Hi All, I'm trying to get part of a filename and my skill with regular expression are lacking. I know I need to use SED but have no idea how to use it. I'm hoping that someone can help me out. The file names would be: prefix<partwewant>suffix.extension the prefix and suffix are always 3... (4 Replies)
Discussion started by: imonkey
4 Replies

8. UNIX for Advanced & Expert Users

query display number lines or records present in file only numeric value -without filename

Hi all Thanks in advance........... Please help me for this issue............ I have a file it has 11 records . I used the command like .... >$ wc -l file 11 file I'm getting output like 11 file (no.of records along with filename) here my requirement is, I want to display only... (3 Replies)
Discussion started by: ksrivani
3 Replies

9. UNIX for Dummies Questions & Answers

sort files by numeric filename

dear all, i have .dat files named as: 34.dat 2.dat 16.dat 107.dat i would like to sort them by their filenames as: 2.dat 16.dat 34.dat 107.dat i have tried numerous combinations of sort and ls command (in vain) to obtain : 107.dat 16.dat 2.dat 34.dat (1 Reply)
Discussion started by: chen.xiao.po
1 Replies

10. Shell Programming and Scripting

With Regex Spliting the string into Alphanumeric and Numeric part

Hi there With shell script I'm trying to split the string into two parts. One is alphanumeric part, the other one is a numeric part. dummy_postcode_1 = 'SL1' --> res_alpha = 'SL' and res_numeric = '1' dummy_postcode_2 = 'S053' --> res_alpha = 'S' and res_numeric = '053' ... (1 Reply)
Discussion started by: ozgurgul
1 Replies
Login or Register to Ask a Question