Need help in shell script to trim numeric values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in shell script to trim numeric values
# 1  
Old 02-10-2010
Need help in shell script to trim numeric values

Hello

I am currently working on a shell script which actually needs to pull some file

from a server ,


The filenames will have the extension with date/time stamp , i need to trim that and name it to proper format

Example :


xyz_20091108_22142365.gzip


i need to remove the numbers from that and name it to xyz.gzip

i know i can use mv for these but i have huge number of files with different names and with different time stamps .


Please suggest a method to trim the numeric values(date/timestamp) without using a mv command.

Thanks for your help!!
# 2  
Old 02-10-2010
Code:
file=xyz_20091108_22142365.gzip
newfile=${file%%_*}.gzip


Or, if the suffix could change:
Code:
file=xyz_20091108_22142365.gzip
newfile=${file%%_*}.${file##*.}

# 3  
Old 02-10-2010
Quote:
Originally Posted by cfajohnson
Code:
file=xyz_20091108_22142365.gzip
newfile=${file%%_*}.gzip


Or, if the suffix could change:
Code:
file=xyz_20091108_22142365.gzip
newfile=${file%%_*}.${file##*.}


Thanks for your reply,,

it displays the file name , but i need to have the new file name in the directory instead of the one which has the timestamp

xyz_20091108_22142365.gzip should be replaced by xyz.zip in the same directory

but it displays the file name but the actual file is not there.

Thanks for your help again !!
# 4  
Old 02-10-2010
Code:
mv "$file" "$newfile"

# 5  
Old 02-16-2010
Quote:
Originally Posted by cfajohnson
Code:
mv "$file" "$newfile"

Thanks for your reply :


if the file name is xyz_xyzxyz_xyz_2009565213_20085778992_.lst.gzip

can you please let me know can you you trim the numeric values

output should be :


xyz_xyzxyz_xyz.lst.gzip

Thanks again!
# 6  
Old 02-16-2010
something like this:

Code:
 
echo "xyz_xyzxyz_xyz_2009565213.lst.gzip" |  sed 's/_[0-9][_0-9]*//g'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to trim values in sybase ase?

HI Team I am using Sybase ASE15.7 version. Below is the sample column values . http://abc.lifeline.airs.com/support/ https://xyzbre.lifeline.airs.com/video/ Would like to know how to Trim http:// and https:// from above list of example Remove characters after first / Include only the... (3 Replies)
Discussion started by: Perlbaby
3 Replies

2. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

3. UNIX for Dummies Questions & Answers

Script to Count the Numeric Values and get the Total

Can anyone help me in this? Here is the Secenario. I need to count the Numerical vaues from the below output Item processed: 1401 Item processed: 2839 Item processed: 1261 Item processed: 2584 Item processed: 2 Item processed: 988 Item processed: 1 Item processed: 2119 ... (3 Replies)
Discussion started by: Padmanabhan
3 Replies

4. Shell Programming and Scripting

TRIM a string in shell script

HI, I have a string "NZ-deploy-mode-1.15-Linux.x86_64.rpm" I want to get the string before -1 ie "NZ-deploy-mode" Input is "NZ-deploy-mode-1.15-Linux.x86_64.rpm" expected output is "NZ-deploy-mode" How can I do that in shell script? Thanks in advance. (6 Replies)
Discussion started by: Ananthdoss
6 Replies

5. Shell Programming and Scripting

Can i use trim in shell script ?

Hi, I am stuck at comparing a value from database with a space involved. Condition if (cust_code != "RAMK" && cust_code != "LML") { xxxxxxx xxxxxxx xxxxxxx } the cust_code is from a table and generally has 4 chars...so in the case of LML it comes with default space at the end. ... (1 Reply)
Discussion started by: ramkiran77
1 Replies

6. Shell Programming and Scripting

Use AWK to check for numeric values? (BASH script)

Hi, I'm quite new to scripting, but know a few AWK statements. I have the following line in my script: hostname=`echo $file | awk 'BEGIN{FS=OFS="."}{$NF=""; NF--; print}'` I use this in my script to rename files, which are similar to this: name.mvkf.mkvfm.mkfvm.1 To the... (4 Replies)
Discussion started by: TauntaunHerder
4 Replies

7. Shell Programming and Scripting

How to trim a string in unix shell script

I am reading a string like $/folder1/folder2/filename from a file And I am storing it in a variable say $path. I want to store the path within single quotes in order to use the path within a command. if i set like path="'"$path"'" echo $path It is printing like ' $/folder1/folder2/filename'... (6 Replies)
Discussion started by: Shri123
6 Replies

8. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

9. Programming

numeric values ending in 'U'

I am getting back on the C++ programming after many years away. I recently received an SDK that has code like this where numeric values end in 'U'. What does this mean? if ((ptr % 16U) == 0U) return buffer; (3 Replies)
Discussion started by: sneakyimp
3 Replies

10. Shell Programming and Scripting

Reversing and trim a String through SHELL script

All I want to reverse and trim a string using UNIX shell scripts.Iam using Bourne shells. Can you help me? Thanx in advance Regards Deepak (5 Replies)
Discussion started by: DeepakXavier
5 Replies
Login or Register to Ask a Question